Fix SwigPyObject->dict memory leak
The following patch attempt to fix a memory leak happening when a random class attribute is set. The internal instance dictionary is created but never freed. This fixes the problem for me, although I am not sure the patch is correct. <code> p = MySWIGClass() p.random_attribute = 0 </code> Valgrind report: ==18267== 280 bytes in 1 blocks are definitely lost in loss record 1,372 of 1,780 ==18267== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==18267== by 0x3A90A885DC: PyObject_Malloc (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90B101A8: _PyObject_GC_Malloc (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90B102AC: _PyObject_GC_New (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90A80943: PyDict_New (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90A6E8FC: PyFrame_New (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90AE1A65: PyEval_EvalCodeEx (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90AE088E: PyEval_EvalFrameEx (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90AE21DC: PyEval_EvalCodeEx (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90AE22E1: PyEval_EvalCode (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90AFB71E: ??? (in /usr/lib64/libpython2.7.so.1.0) ==18267== by 0x3A90AFC8DD: PyRun_FileExFlags (in /usr/lib64/libpython2.7.so.1.0) ==18267==
This commit is contained in:
parent
92b88db7ab
commit
3983d7b230
1 changed files with 1 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ SWIGINTERN void \
|
|||
wrapper##_closure(PyObject *a) { \
|
||||
SwigPyObject *sobj; \
|
||||
sobj = (SwigPyObject *)a; \
|
||||
Py_XDECREF(sobj->dict); \
|
||||
if (sobj->own) { \
|
||||
PyObject *o = wrapper(a, NULL); \
|
||||
Py_XDECREF(o); \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue