* [PATCH] Fix memory leaks in libxc python bindings
@ 2009-09-29 16:54 Jiri Denemark
2009-09-29 17:00 ` Konrad Rzeszutek Wilk
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Denemark @ 2009-09-29 16:54 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 312 bytes --]
Hi,
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@redhat.com>
[-- Attachment #2: xc-leak.patch --]
[-- Type: text/plain, Size: 1772 bytes --]
diff -r bd376919f03a tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Tue Sep 29 11:28:33 2009 +0100
+++ b/tools/python/xen/lowlevel/xc/xc.c Tue Sep 29 18:45:33 2009 +0200
@@ -387,8 +387,11 @@
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 @@
{
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
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Fix memory leaks in libxc python bindings
2009-09-29 16:54 [PATCH] Fix memory leaks in libxc python bindings Jiri Denemark
@ 2009-09-29 17:00 ` Konrad Rzeszutek Wilk
2009-09-29 19:18 ` Jiri Denemark
0 siblings, 1 reply; 3+ messages in thread
From: Konrad Rzeszutek Wilk @ 2009-09-29 17:00 UTC (permalink / raw)
To: xen-devel
On Tue, Sep 29, 2009 at 06:54:09PM +0200, Jiri Denemark wrote:
> Hi,
>
> Reference counters are not correctly decreased for python object in several
I am curious how did you find this? Is there a python 'valgrind' that
can help track this? Or is there a python flag to be report such abnormalities?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix memory leaks in libxc python bindings
2009-09-29 17:00 ` Konrad Rzeszutek Wilk
@ 2009-09-29 19:18 ` Jiri Denemark
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Denemark @ 2009-09-29 19:18 UTC (permalink / raw)
To: xen-devel
> > Reference counters are not correctly decreased for python object in several
>
> I am curious how did you find this? Is there a python 'valgrind' that
> can help track this? Or is there a python flag to be report such abnormalities?
None that I know of. I just used the source code. I found it because long
running xend managed by libvirt was consuming increasing amount of memory.
From the only repeatedly executed command virsh list I got to xm info and
xc_physinfo(). And then I just looked for all other calls to PyDict_* and
PyList_Append and fixed them.
Jirka
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-09-29 19:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-29 16:54 [PATCH] Fix memory leaks in libxc python bindings Jiri Denemark
2009-09-29 17:00 ` Konrad Rzeszutek Wilk
2009-09-29 19:18 ` Jiri Denemark
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.