aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGianni Tedesco <gianni.tedesco@citrix.com>2011-01-11 18:54:44 +0000
committerGianni Tedesco <gianni.tedesco@citrix.com>2011-01-11 18:54:44 +0000
commit5644ab84f714d6e248979e3800b2d48a43be0eaf (patch)
treefa39a6305de72872c23b4e28b4b29fa2247f3631
parentbdf80c61cb1f705c0f4472cbd7694c99bca9b0c5 (diff)
downloadxen-5644ab84f714d6e248979e3800b2d48a43be0eaf.tar.gz
xen-5644ab84f714d6e248979e3800b2d48a43be0eaf.tar.bz2
xen-5644ab84f714d6e248979e3800b2d48a43be0eaf.zip
tools/python/pyxl: Fix reference counting of Py_(None|True|False)
The incorrect refcounting causes the python interpreter to crash Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
-rw-r--r--tools/python/genwrap.py5
-rw-r--r--tools/python/xen/lowlevel/xl/xl.c12
2 files changed, 15 insertions, 2 deletions
diff --git a/tools/python/genwrap.py b/tools/python/genwrap.py
index 7875d46522..fd2d39dd6e 100644
--- a/tools/python/genwrap.py
+++ b/tools/python/genwrap.py
@@ -51,7 +51,10 @@ def py_attrib_get(ty, f):
l.append('static PyObject *py_%s_%s_get(Py_%s *self, void *priv)'%(ty.rawname, f.name, ty.rawname))
l.append('{')
if t == TYPE_BOOL:
- l.append(' return (self->obj.%s) ? Py_True : Py_False;'%f.name)
+ l.append(' PyObject *ret;')
+ l.append(' ret = (self->obj.%s) ? Py_True : Py_False;'%f.name)
+ l.append(' Py_INCREF(ret);')
+ l.append(' return ret;')
elif t == TYPE_INT:
l.append(' return genwrap__ll_get(self->obj.%s);'%f.name)
elif t == TYPE_UINT:
diff --git a/tools/python/xen/lowlevel/xl/xl.c b/tools/python/xen/lowlevel/xl/xl.c
index 1fef9587cc..058e7d26f1 100644
--- a/tools/python/xen/lowlevel/xl/xl.c
+++ b/tools/python/xen/lowlevel/xl/xl.c
@@ -97,8 +97,10 @@ int genwrap__string_set(PyObject *v, char **str)
PyObject *genwrap__string_get(char **str)
{
- if ( NULL == *str )
+ if ( NULL == *str ) {
+ Py_INCREF(Py_None);
return Py_None;
+ }
return PyString_FromString(*str);
}
@@ -377,6 +379,7 @@ static PyObject *pyxl_list_domains(XlObject *self)
if ( NULL == di )
goto err_mem;
memcpy(&di->obj, cur, sizeof(di->obj));
+ /* SetItem steals a reference */
PyList_SetItem(list, i, (PyObject *)di);
}
@@ -413,6 +416,7 @@ static PyObject *pyxl_domain_shutdown(XlObject *self, PyObject *args)
PyErr_SetString(xl_error_obj, "cannot shutdown domain");
return NULL;
}
+ Py_INCREF(Py_None);
return Py_None;
}
@@ -425,6 +429,7 @@ static PyObject *pyxl_domain_destroy(XlObject *self, PyObject *args)
PyErr_SetString(xl_error_obj, "cannot destroy domain");
return NULL;
}
+ Py_INCREF(Py_None);
return Py_None;
}
@@ -437,6 +442,7 @@ static PyObject *pyxl_domain_pause(XlObject *self, PyObject *args)
PyErr_SetString(xl_error_obj, "cannot pause domain");
return NULL;
}
+ Py_INCREF(Py_None);
return Py_None;
}
@@ -449,6 +455,7 @@ static PyObject *pyxl_domain_unpause(XlObject *self, PyObject *args)
PyErr_SetString(xl_error_obj, "cannot unpause domain");
return NULL;
}
+ Py_INCREF(Py_None);
return Py_None;
}
@@ -462,6 +469,7 @@ static PyObject *pyxl_domain_rename(XlObject *self, PyObject *args)
PyErr_SetString(xl_error_obj, "cannot rename domain");
return NULL;
}
+ Py_INCREF(Py_None);
return Py_None;
}
@@ -481,6 +489,7 @@ static PyObject *pyxl_pci_add(XlObject *self, PyObject *args)
PyErr_SetString(xl_error_obj, "cannot add pci device");
return NULL;
}
+ Py_INCREF(Py_None);
return Py_None;
}
@@ -501,6 +510,7 @@ static PyObject *pyxl_pci_del(XlObject *self, PyObject *args)
PyErr_SetString(xl_error_obj, "cannot remove pci device");
return NULL;
}
+ Py_INCREF(Py_None);
return Py_None;
}