[libvirt] [PATCH 0/3] python: Fix memory leaks

From: Alex Jia <ajia@redhat.com> This series patches fix memory leaks issues. Detected by valgrind. Alex Jia (3): * python/libvirt-override.c: fix memory leaks on libvirt_virDomainBlockStatsFlags. * python/libvirt-override.c: fix memory leaks on libvirt_virDomainGetSchedulerParameters and libvirt_virDomainGetSchedulerParametersFlags. * python/libvirt-override.c: fix memory leaks on libvirt_virDomainGetMemoryParameters. Signed-off-by: Alex Jia <ajia@redhat.com>

From: Alex Jia <ajia@redhat.com> Detected by valgrind. Leaks introduced in commit 62094f7 and commit c5cf6e1. * python/libvirt-override.c: fix memory leaks on libvirt_virDomainGetSchedulerParameters and libvirt_virDomainGetSchedulerParametersFlags. * actual valgrind result: ==26037== 112 bytes in 3 blocks are definitely lost in loss record 1,461 of 2,085 ==26037== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==26037== by 0x39E1A85EC3: PyObject_Malloc (obmalloc.c:935) ==26037== by 0x39E1A77831: _PyLong_New (longobject.c:75) ==26037== by 0x39E1A79EB6: PyLong_FromLongLong (longobject.c:864) ==26037== by 0xB8FA0E0: libvirt_virDomainGetSchedulerParameters (libvirt-override.c:353) ==26037== by 0x39E1ADE7F3: PyEval_EvalFrameEx (ceval.c:3794) ==26037== by 0x39E1ADF99E: PyEval_EvalFrameEx (ceval.c:3880) ==26037== by 0x39E1AE0466: PyEval_EvalCodeEx (ceval.c:3044) ==26037== by 0x39E1AE0541: PyEval_EvalCode (ceval.c:545) ==26037== by 0x39E1AFB88B: run_mod (pythonrun.c:1351) ==26037== by 0x39E1AFB95F: PyRun_FileExFlags (pythonrun.c:1337) ==26037== by 0x39E1AFCE4B: PyRun_SimpleFileExFlags (pythonrun.c:941) ==26037== ==26037== 112 bytes in 3 blocks are definitely lost in loss record 1,462 of 2,085 ==26037== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==26037== by 0x39E1A85EC3: PyObject_Malloc (obmalloc.c:935) ==26037== by 0x39E1A77831: _PyLong_New (longobject.c:75) ==26037== by 0x39E1A79EB6: PyLong_FromLongLong (longobject.c:864) ==26037== by 0xB8F9AF8: libvirt_virDomainGetSchedulerParametersFlags (libvirt-override.c:435) ==26037== by 0x39E1ADE7F3: PyEval_EvalFrameEx (ceval.c:3794) ==26037== by 0x39E1ADF99E: PyEval_EvalFrameEx (ceval.c:3880) ==26037== by 0x39E1AE0466: PyEval_EvalCodeEx (ceval.c:3044) ==26037== by 0x39E1AE0541: PyEval_EvalCode (ceval.c:545) ==26037== by 0x39E1AFB88B: run_mod (pythonrun.c:1351) ==26037== by 0x39E1AFB95F: PyRun_FileExFlags (pythonrun.c:1337) ==26037== by 0x39E1AFCE4B: PyRun_SimpleFileExFlags (pythonrun.c:941) ==26037== ==26037== 151 bytes in 3 blocks are definitely lost in loss record 1,512 of 2,085 ==26037== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==26037== by 0x39E1A85EC3: PyObject_Malloc (obmalloc.c:935) ==26037== by 0x39E1A9053C: PyString_FromString (stringobject.c:138) ==26037== by 0xB8FA0F4: libvirt_virDomainGetSchedulerParameters (libvirt-override.c:370) ==26037== by 0x39E1ADE7F3: PyEval_EvalFrameEx (ceval.c:3794) ==26037== by 0x39E1ADF99E: PyEval_EvalFrameEx (ceval.c:3880) ==26037== by 0x39E1AE0466: PyEval_EvalCodeEx (ceval.c:3044) ==26037== by 0x39E1AE0541: PyEval_EvalCode (ceval.c:545) ==26037== by 0x39E1AFB88B: run_mod (pythonrun.c:1351) ==26037== by 0x39E1AFB95F: PyRun_FileExFlags (pythonrun.c:1337) ==26037== by 0x39E1AFCE4B: PyRun_SimpleFileExFlags (pythonrun.c:941) ==26037== by 0x39E1B094CE: Py_Main (main.c:577) ==26037== 151 bytes in 3 blocks are definitely lost in loss record 1,513 of 2,085 ==26037== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==26037== by 0x39E1A85EC3: PyObject_Malloc (obmalloc.c:935) ==26037== by 0x39E1A9053C: PyString_FromString (stringobject.c:138) ==26037== by 0xB8F9B0C: libvirt_virDomainGetSchedulerParametersFlags (libvirt-override.c:452) ==26037== by 0x39E1ADE7F3: PyEval_EvalFrameEx (ceval.c:3794) ==26037== by 0x39E1ADF99E: PyEval_EvalFrameEx (ceval.c:3880) ==26037== by 0x39E1AE0466: PyEval_EvalCodeEx (ceval.c:3044) ==26037== by 0x39E1AE0541: PyEval_EvalCode (ceval.c:545) ==26037== by 0x39E1AFB88B: run_mod (pythonrun.c:1351) ==26037== by 0x39E1AFB95F: PyRun_FileExFlags (pythonrun.c:1337) ==26037== by 0x39E1AFCE4B: PyRun_SimpleFileExFlags (pythonrun.c:941) ==26037== by 0x39E1B094CE: Py_Main (main.c:577) RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=770940 Signed-off-by: Alex Jia <ajia@redhat.com> --- python/libvirt-override.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/python/libvirt-override.c b/python/libvirt-override.c index d2aad0f..fbf325a 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -369,6 +369,8 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); + Py_DECREF(key); + Py_DECREF(val); } free(params); return(info); @@ -451,6 +453,8 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); + Py_DECREF(key); + Py_DECREF(val); } free(params); return(info); -- 1.7.1

On 12/31/2011 03:29 AM, ajia@redhat.com wrote:
From: Alex Jia <ajia@redhat.com>
Detected by valgrind. Leaks introduced in commit 62094f7 and commit c5cf6e1.
key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); + Py_DECREF(key); + Py_DECREF(val);
Can PyDict_SetItem() fail? If so, shouldn't we be recovering from that failure by cleaning up memory and returning a proper error, rather than blindly proceeding on? We ought to fix all PyDict_SetItem clients in the same way as part of a global cleanup patch in the python directory, which will have the side effect of fixing the memory leaks in the process. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Hi Eric, Thanks for your comment, the PyDict_SetItem still works well for me, I can get a expected result by calling related python binding API, Doesn't it work for you? In addition, you mean we need a cleanup patch to fix all of memory leaks issues, right? or need to define a global cleanup function to do this? For side effect, in fact, I can't understand this now :( maybe, you may give me more details. Thanks a lot! Alex ----- Original Message ----- From: "Eric Blake" <eblake@redhat.com> To: ajia@redhat.com Cc: libvir-list@redhat.com Sent: Sunday, January 1, 2012 7:52:21 AM Subject: Re: [libvirt] [PATCH 1/3] python: Fix memory leaks on libvirt_virDomainGetSchedulerParameters On 12/31/2011 03:29 AM, ajia@redhat.com wrote:
From: Alex Jia <ajia@redhat.com>
Detected by valgrind. Leaks introduced in commit 62094f7 and commit c5cf6e1.
key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); + Py_DECREF(key); + Py_DECREF(val);
Can PyDict_SetItem() fail? If so, shouldn't we be recovering from that failure by cleaning up memory and returning a proper error, rather than blindly proceeding on? We ought to fix all PyDict_SetItem clients in the same way as part of a global cleanup patch in the python directory, which will have the side effect of fixing the memory leaks in the process. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

From: Alex Jia <ajia@redhat.com> Detected by valgrind. Leaks introduced in commit 9b38239. * python/libvirt-override.c: fix memory leaks on libvirt_virDomainGetMemoryParameters. * actual valgrind result: ==2212== 120 bytes in 3 blocks are definitely lost in loss record 1,466 of 2,083 ==2212== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==2212== by 0x39E1A85EC3: PyObject_Malloc (obmalloc.c:935) ==2212== by 0x39E1A77831: _PyLong_New (longobject.c:75) ==2212== by 0x39E1A79EB6: PyLong_FromLongLong (longobject.c:864) ==2212== by 0xB8F8D98: libvirt_virDomainGetMemoryParameters (libvirt-override.c:982) ==2212== by 0x39E1ADE7F3: PyEval_EvalFrameEx (ceval.c:3794) ==2212== by 0x39E1ADF99E: PyEval_EvalFrameEx (ceval.c:3880) ==2212== by 0x39E1AE0466: PyEval_EvalCodeEx (ceval.c:3044) ==2212== by 0x39E1AE0541: PyEval_EvalCode (ceval.c:545) ==2212== by 0x39E1AFB88B: run_mod (pythonrun.c:1351) ==2212== by 0x39E1AFB95F: PyRun_FileExFlags (pythonrun.c:1337) ==2212== by 0x39E1AFCE4B: PyRun_SimpleFileExFlags (pythonrun.c:941) ==2212== ==2212== 155 bytes in 3 blocks are definitely lost in loss record 1,514 of 2,083 ==2212== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==2212== by 0x39E1A85EC3: PyObject_Malloc (obmalloc.c:935) ==2212== by 0x39E1A9053C: PyString_FromString (stringobject.c:138) ==2212== by 0xB8F8DAC: libvirt_virDomainGetMemoryParameters (libvirt-override.c:999) ==2212== by 0x39E1ADE7F3: PyEval_EvalFrameEx (ceval.c:3794) ==2212== by 0x39E1ADF99E: PyEval_EvalFrameEx (ceval.c:3880) ==2212== by 0x39E1AE0466: PyEval_EvalCodeEx (ceval.c:3044) ==2212== by 0x39E1AE0541: PyEval_EvalCode (ceval.c:545) ==2212== by 0x39E1AFB88B: run_mod (pythonrun.c:1351) ==2212== by 0x39E1AFB95F: PyRun_FileExFlags (pythonrun.c:1337) ==2212== by 0x39E1AFCE4B: PyRun_SimpleFileExFlags (pythonrun.c:941) ==2212== by 0x39E1B094CE: Py_Main (main.c:577) RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=770941 Signed-off-by: Alex Jia <ajia@redhat.com> --- python/libvirt-override.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/python/libvirt-override.c b/python/libvirt-override.c index fbf325a..178745b 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -998,6 +998,8 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); + Py_DECREF(key); + Py_DECREF(val); } free(params); return(info); -- 1.7.1

From: Alex Jia <ajia@redhat.com> Detected by valgrind. Leaks introuduced in commit f4c331a. * python/libvirt-override.c: fix memory leaks on libvirt_virDomainBlockStatsFlags. * actual valgrind result: ==10849== 160 bytes in 5 blocks are definitely lost in loss record 1,525 of 2,083 ==10849== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==10849== by 0x39E1A85EC3: PyObject_Malloc (obmalloc.c:935) ==10849== by 0x39E1A77831: _PyLong_New (longobject.c:75) ==10849== by 0x39E1A79EB6: PyLong_FromLongLong (longobject.c:864) ==10849== by 0xB8FAD08: libvirt_virDomainBlockStatsFlags (libvirt-override.c:160) ==10849== by 0x39E1ADE7F3: PyEval_EvalFrameEx (ceval.c:3794) ==10849== by 0x39E1ADF99E: PyEval_EvalFrameEx (ceval.c:3880) ==10849== by 0x39E1AE0466: PyEval_EvalCodeEx (ceval.c:3044) ==10849== by 0x39E1AE0541: PyEval_EvalCode (ceval.c:545) ==10849== by 0x39E1AFB88B: run_mod (pythonrun.c:1351) ==10849== by 0x39E1AFB95F: PyRun_FileExFlags (pythonrun.c:1337) ==10849== by 0x39E1AFCE4B: PyRun_SimpleFileExFlags (pythonrun.c:941) ==10849== ==10849== 258 bytes in 5 blocks are definitely lost in loss record 1,590 of 2,083 ==10849== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==10849== by 0x39E1A85EC3: PyObject_Malloc (obmalloc.c:935) ==10849== by 0x39E1A9053C: PyString_FromString (stringobject.c:138) ==10849== by 0xB8FAD1C: libvirt_virDomainBlockStatsFlags (libvirt-override.c:177) ==10849== by 0x39E1ADE7F3: PyEval_EvalFrameEx (ceval.c:3794) ==10849== by 0x39E1ADF99E: PyEval_EvalFrameEx (ceval.c:3880) ==10849== by 0x39E1AE0466: PyEval_EvalCodeEx (ceval.c:3044) ==10849== by 0x39E1AE0541: PyEval_EvalCode (ceval.c:545) ==10849== by 0x39E1AFB88B: run_mod (pythonrun.c:1351) ==10849== by 0x39E1AFB95F: PyRun_FileExFlags (pythonrun.c:1337) ==10849== by 0x39E1AFCE4B: PyRun_SimpleFileExFlags (pythonrun.c:941) ==10849== by 0x39E1B094CE: Py_Main (main.c:577) Signed-off-by: Alex Jia <ajia@redhat.com> --- python/libvirt-override.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 178745b..a138090 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -176,6 +176,8 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); + Py_DECREF(key); + Py_DECREF(val); } free(params); -- 1.7.1
participants (3)
-
ajia@redhat.com
-
Alex Jia
-
Eric Blake