# HG changeset patch
# User Keir Fraser <keir@xxxxxxxxxxxxx>
# Date 1174236592 0
# Node ID 7521c87983e0dd1a30a80f68bf3b73765997bbc0
# Parent 9df276596cbba10c1129cbee92d150b5aa00d960
xend: Fix Py_BuildValue() invocation (don't use I specifier).
Various error-handlign cleanup and fix a reference leakage.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
tools/python/xen/lowlevel/xc/xc.c | 46 +++++++++++++++++++++++---------------
1 files changed, 28 insertions(+), 18 deletions(-)
diff -r 9df276596cbb -r 7521c87983e0 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Sun Mar 18 12:06:50 2007 +0000
+++ b/tools/python/xen/lowlevel/xc/xc.c Sun Mar 18 16:49:52 2007 +0000
@@ -50,17 +50,21 @@ static PyObject *pyxc_error_to_exception
const xc_error *err = xc_get_last_error();
const char *desc = xc_error_code_to_desc(err->code);
- if (err->code == XC_ERROR_NONE)
+ if ( err->code == XC_ERROR_NONE )
return PyErr_SetFromErrno(xc_error_obj);
- if (err->message[0] != '\0')
+ if ( err->message[0] != '\0' )
pyerr = Py_BuildValue("(iss)", err->code, desc, err->message);
else
pyerr = Py_BuildValue("(is)", err->code, desc);
xc_clear_last_error();
- PyErr_SetObject(xc_error_obj, pyerr);
+ if ( pyerr != NULL )
+ {
+ PyErr_SetObject(xc_error_obj, pyerr);
+ Py_DECREF(pyerr);
+ }
return NULL;
}
@@ -70,13 +74,13 @@ static PyObject *pyxc_domain_dumpcore(Xc
uint32_t dom;
char *corefile;
- if (!PyArg_ParseTuple(args, "is", &dom, &corefile))
+ if ( !PyArg_ParseTuple(args, "is", &dom, &corefile) )
return NULL;
if ( (corefile == NULL) || (corefile[0] == '\0') )
return NULL;
- if (xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0)
+ if ( xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0 )
return pyxc_error_to_exception();
Py_INCREF(zero);
@@ -168,10 +172,10 @@ static PyObject *pyxc_domain_shutdown(Xc
{
uint32_t dom, reason;
- if (!PyArg_ParseTuple(args, "ii", &dom, &reason))
+ if ( !PyArg_ParseTuple(args, "ii", &dom, &reason) )
return NULL;
- if (xc_domain_shutdown(self->xc_handle, dom, reason) != 0)
+ if ( xc_domain_shutdown(self->xc_handle, dom, reason) != 0 )
return pyxc_error_to_exception();
Py_INCREF(zero);
@@ -183,10 +187,10 @@ static PyObject *pyxc_domain_resume(XcOb
uint32_t dom;
int fast;
- if (!PyArg_ParseTuple(args, "ii", &dom, &fast))
- return NULL;
-
- if (xc_domain_resume(self->xc_handle, dom, fast) != 0)
+ if ( !PyArg_ParseTuple(args, "ii", &dom, &fast) )
+ return NULL;
+
+ if ( xc_domain_resume(self->xc_handle, dom, fast) != 0 )
return pyxc_error_to_exception();
Py_INCREF(zero);
@@ -282,7 +286,7 @@ static PyObject *pyxc_domain_getinfo(XcO
PyObject *args,
PyObject *kwds)
{
- PyObject *list, *info_dict;
+ PyObject *list, *info_dict, *pyhandle;
uint32_t first_dom = 0;
int max_doms = 1024, nr_doms, i, j;
@@ -308,12 +312,9 @@ static PyObject *pyxc_domain_getinfo(XcO
list = PyList_New(nr_doms);
for ( i = 0 ; i < nr_doms; i++ )
{
- PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
- for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
- PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
info_dict = Py_BuildValue(
- "{s:i,s:I,s:I,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
- ",s:k,s:L,s:k,s:i,s:I}",
+ "{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
+ ",s:k,s:L,s:k,s:i,s:i}",
"domid", (int)info[i].domid,
"online_vcpus", info[i].nr_online_vcpus,
"max_vcpu_id", info[i].max_vcpu_id,
@@ -324,12 +325,21 @@ static PyObject *pyxc_domain_getinfo(XcO
"paused", info[i].paused,
"blocked", info[i].blocked,
"running", info[i].running,
-
"mem_kb", info[i].nr_pages*(XC_PAGE_SIZE/1024),
"cpu_time", (long long)info[i].cpu_time,
"maxmem_kb", info[i].max_memkb,
"ssidref", (int)info[i].ssidref,
"shutdown_reason", info[i].shutdown_reason);
+ pyhandle = PyList_New(sizeof(xen_domain_handle_t));
+ if ( (pyhandle == NULL) || (info_dict == NULL) )
+ {
+ Py_DECREF(list);
+ if ( pyhandle != NULL ) { Py_DECREF(pyhandle); }
+ if ( info_dict != NULL ) { Py_DECREF(info_dict); }
+ return NULL;
+ }
+ for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
+ PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
PyDict_SetItemString(info_dict, "handle", pyhandle);
Py_DECREF(pyhandle);
PyList_SetItem(list, i, info_dict);
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|