[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xend: Fix memory leaks in libxc python bindings



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1254296697 -3600
# Node ID 516d7de8e9a1d0470c57df983a45c74338c70326
# Parent  c6b22d0d1e90d5cfe608e932096a4adb96b8aa3f
xend: Fix memory leaks in libxc python bindings

Reference counters are not correctly decreased for python object in
several places in python bindings for libxc. Most of them are around
PyList_Append(), which unlike PyList_SetItem() does increment
reference counter of the object being added to a list.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 tools/python/xen/lowlevel/xc/xc.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff -r c6b22d0d1e90 -r 516d7de8e9a1 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Wed Sep 30 08:43:34 2009 +0100
+++ b/tools/python/xen/lowlevel/xc/xc.c Wed Sep 30 08:44:57 2009 +0100
@@ -387,8 +387,11 @@ static PyObject *pyxc_vcpu_getinfo(XcObj
     cpulist = PyList_New(0);
     for ( i = 0; cpumap != 0; i++ )
     {
-        if ( cpumap & 1 )
-            PyList_Append(cpulist, PyInt_FromLong(i));
+        if ( cpumap & 1 ) {
+            PyObject *pyint = PyInt_FromLong(i);
+            PyList_Append(cpulist, pyint);
+            Py_DECREF(pyint);
+        }
         cpumap >>= 1;
     }
     PyDict_SetItemString(info_dict, "cpumap", cpulist);
@@ -1104,22 +1107,31 @@ static PyObject *pyxc_physinfo(XcObject 
     {
         PyObject *cpus = PyList_New(0);
         for ( j = 0; j <= max_cpu_id; j++ )
-            if ( i == map[j])
-                PyList_Append(cpus, PyInt_FromLong(j));
+            if ( i == map[j]) {
+                PyObject *pyint = PyInt_FromLong(j);
+                PyList_Append(cpus, pyint);
+                Py_DECREF(pyint);
+            }
         PyList_Append(node_to_cpu_obj, cpus); 
+        Py_DECREF(cpus);
     }
 
     node_to_memory_obj = PyList_New(0);
 
     for ( i = 0; i < info.nr_nodes; i++ )
     {
+        PyObject *pyint;
+
         xc_availheap(self->xc_handle, 0, 0, i, &free_heap);
-        PyList_Append(node_to_memory_obj,
-                      PyInt_FromLong(free_heap / 1024));
+        pyint = PyInt_FromLong(free_heap / 1024);
+        PyList_Append(node_to_memory_obj, pyint);
+        Py_DECREF(pyint);
     }
 
     PyDict_SetItemString(ret_obj, "node_to_cpu", node_to_cpu_obj);
+    Py_DECREF(node_to_cpu_obj);
     PyDict_SetItemString(ret_obj, "node_to_memory", node_to_memory_obj);
+    Py_DECREF(node_to_memory_obj);
  
     return ret_obj;
 #undef MAX_CPU_ID

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.