[PATCH 1/3] python: Fix memory leaks on libvirt_virDomainGetSchedulerParameters

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

 



From: Alex Jia <ajia@xxxxxxxxxx>

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@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]