]> Git Repo - binutils.git/commitdiff
Fix a bunch of python leaks due to missing calls to tp_free in *_dealloc functions.
authorPhilippe Waroquiers <[email protected]>
Sun, 17 Nov 2019 21:48:48 +0000 (22:48 +0100)
committerPhilippe Waroquiers <[email protected]>
Mon, 18 Nov 2019 19:14:26 +0000 (20:14 +0100)
valgrind reports leaks in many python tests, such as:
==17162== VALGRIND_GDB_ERROR_BEGIN
==17162== 8,208 (5,472 direct, 2,736 indirect) bytes in 57 blocks are definitely lost in loss record 7,551 of 7,679
==17162==    at 0x4835753: malloc (vg_replace_malloc.c:307)
==17162==    by 0x6EAFD1: _PyObject_New (object.c:279)
==17162==    by 0x4720E6: blpy_iter(_object*) (py-block.c:92)
==17162==    by 0x698772: PyObject_GetIter (abstract.c:2577)
==17162==    by 0x2343BE: _PyEval_EvalFrameDefault (ceval.c:3159)
==17162==    by 0x22E9E2: function_code_fastcall (call.c:283)
==17162==    by 0x2340A8: _PyObject_Vectorcall (abstract.h:127)
==17162==    by 0x2340A8: call_function (ceval.c:4987)
==17162==    by 0x2340A8: _PyEval_EvalFrameDefault (ceval.c:3486)
==17162==    by 0x22E9E2: function_code_fastcall (call.c:283)
==17162==    by 0x82172B: _PyObject_Vectorcall (abstract.h:127)
==17162==    by 0x82172B: method_vectorcall (classobject.c:67)
==17162==    by 0x6AF474: _PyObject_Vectorcall (abstract.h:127)
==17162==    by 0x6AF474: _PyObject_CallNoArg (abstract.h:153)
==17162==    by 0x6AF474: _PyObject_CallFunctionVa (call.c:914)
==17162==    by 0x6B0673: callmethod (call.c:1010)
==17162==    by 0x6B0673: _PyObject_CallMethod_SizeT (call.c:1103)
==17162==    by 0x477DFE: gdb_PyObject_CallMethod<> (python-internal.h:182)
==17162==    by 0x477DFE: get_py_iter_from_func(_object*, char const*) (py-framefilter.c:272)
==17162==    by 0x4791B4: py_print_args (py-framefilter.c:706)
==17162==    by 0x4791B4: py_print_frame(_object*, enum_flags<frame_filter_flag>, ext_lang_frame_args, ui_out*, int, htab*) (py-framefilter.c:960)
==17162==    by 0x47A130: gdbpy_apply_frame_filter(extension_language_defn const*, frame_info*, enum_flags<frame_filter_flag>, ext_lang_frame_args, ui_out*, int, int) (py-framefilter.c:1236)
==17162==    by 0x369C39: apply_ext_lang_frame_filter(frame_info*, enum_flags<frame_filter_flag>, ext_lang_frame_args, ui_out*, int, int) (extension.c:563)
==17162==    by 0x4EC9C9: backtrace_command_1 (stack.c:2031)
==17162==    by 0x4EC9C9: backtrace_command(char const*, int) (stack.c:2183)
...

Most of the leaks in python tests are due to the fact that many
PyObject xxxxx_dealloc functions are missing the line to free self
or obj such as:
   Py_TYPE (self)->tp_free (self);
or
   Py_TYPE (obj)->tp_free (obj);

With this patch, the number of python tests leaking decreases from 52 to 12.

gdb/ChangeLog

2019-11-18  Philippe Waroquiers  <[email protected]>

* python/py-block.c (blpy_dealloc): Call tp_free.
(blpy_block_syms_dealloc): Likewise.
* python/py-finishbreakpoint.c (bpfinishpy_dealloc): Likewise.
* python/py-inferior.c (infpy_dealloc): Likewise.
* python/py-lazy-string.c (stpy_dealloc): Likewise.
* python/py-linetable.c (ltpy_iterator_dealloc): Likewise.
* python/py-symbol.c (sympy_dealloc): Likewise.
* python/py-symtab.c (stpy_dealloc): Likewise.
* python/py-type.c (typy_iterator_dealloc): Likewise.

gdb/ChangeLog
gdb/python/py-block.c
gdb/python/py-finishbreakpoint.c
gdb/python/py-inferior.c
gdb/python/py-lazy-string.c
gdb/python/py-linetable.c
gdb/python/py-symbol.c
gdb/python/py-symtab.c
gdb/python/py-type.c

index 0e17d7c39d86b0fe8f6a1ed9d8753e4d18fc9643..0dfc96ade114d1f2e86c17fbfa36143e88d57bcf 100644 (file)
@@ -1,3 +1,15 @@
+2019-11-18  Philippe Waroquiers  <[email protected]>
+
+       * python/py-block.c (blpy_dealloc): Call tp_free.
+       (blpy_block_syms_dealloc): Likewise.
+       * python/py-finishbreakpoint.c (bpfinishpy_dealloc): Likewise.
+       * python/py-inferior.c (infpy_dealloc): Likewise.
+       * python/py-lazy-string.c (stpy_dealloc): Likewise.
+       * python/py-linetable.c (ltpy_iterator_dealloc): Likewise.
+       * python/py-symbol.c (sympy_dealloc): Likewise.
+       * python/py-symtab.c (stpy_dealloc): Likewise.
+       * python/py-type.c (typy_iterator_dealloc): Likewise.
+
 2019-11-18  Christian Biesinger  <[email protected]>
 
        * symtab.h (struct symbol) <owner>: Initialize explicitly in the
index 4dc47ff169de9af3eea16eb30bc152b1a742175a..54c3be9b1a42e8958040b47f829d5dc75ae11057 100644 (file)
@@ -276,6 +276,7 @@ blpy_dealloc (PyObject *obj)
   if (block->next)
     block->next->prev = block->prev;
   block->block = NULL;
+  Py_TYPE (obj)->tp_free (obj);
 }
 
 /* Given a block, and a block_object that has previously been
@@ -370,6 +371,7 @@ blpy_block_syms_dealloc (PyObject *obj)
   block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) obj;
 
   Py_XDECREF (iter_obj->source);
+  Py_TYPE (obj)->tp_free (obj);
 }
 
 /* Implementation of gdb.Block.is_valid (self) -> Boolean.
index 7f818213bd20376fd52a46d4a3df1543d0888b43..fc20575aea67863cc7e3ff96316aa58f23a31cd8 100644 (file)
@@ -83,6 +83,7 @@ bpfinishpy_dealloc (PyObject *self)
   Py_XDECREF (self_bpfinish->function_value);
   Py_XDECREF (self_bpfinish->return_type);
   Py_XDECREF (self_bpfinish->return_value);
+  Py_TYPE (self)->tp_free (self);
 }
 
 /* Triggered when gdbpy_should_stop is about to execute the `stop' callback
index 28882221a90756903b5c20fd4609284273522bcf..d475263df99d729e6c4eb603de99dc692c3de741 100644 (file)
@@ -856,6 +856,7 @@ infpy_dealloc (PyObject *obj)
     return;
 
   set_inferior_data (inf, infpy_inf_data_key, NULL);
+  Py_TYPE (obj)->tp_free (obj);
 }
 
 /* Clear the INFERIOR pointer in an Inferior object and clear the
index 87c6ceaf2a46bbd0cff25fd6d126c9f0af269439..74f14a94eb9705aa4d76f5e5dd12e8f3fd44d857 100644 (file)
@@ -156,6 +156,7 @@ stpy_dealloc (PyObject *self)
   lazy_string_object *self_string = (lazy_string_object *) self;
 
   xfree (self_string->encoding);
+  Py_TYPE (self)->tp_free (self);
 }
 
 /* Low level routine to create a <gdb.LazyString> object.
index aa43d9e7c746963c312cd6e90a93eb53abef73b7..96a5d3515b665f89f1a14ef7e414d999e52c59d9 100644 (file)
@@ -369,6 +369,7 @@ ltpy_iterator_dealloc (PyObject *obj)
   ltpy_iterator_object *iter_obj = (ltpy_iterator_object *) obj;
 
   Py_DECREF (iter_obj->source);
+  Py_TYPE (obj)->tp_free (obj);
 }
 
 /* Return a reference to the line table iterator.  */
index 647c54b0a5b2799b2f11451e876e6566161ed7d9..b112ce115f1ba25d06d3c3e2f8c602043072d97c 100644 (file)
@@ -357,6 +357,7 @@ sympy_dealloc (PyObject *obj)
   if (sym_obj->next)
     sym_obj->next->prev = sym_obj->prev;
   sym_obj->symbol = NULL;
+  Py_TYPE (obj)->tp_free (obj);
 }
 
 /* Implementation of
index 15af300150597e005af65242f71f18a0772c9e2f..49c6a0ac544d62b9f61b3cac30fb5ccd483b3042 100644 (file)
@@ -253,6 +253,7 @@ stpy_dealloc (PyObject *obj)
   if (symtab->next)
     symtab->next->prev = symtab->prev;
   symtab->symtab = NULL;
+  Py_TYPE (obj)->tp_free (obj);
 }
 
 
index a2fca97a327eee7d09e4a2afc642b17d7f6e1f78..e4350993dd4f9e0a0721504d9ca8a3684c9e5c01 100644 (file)
@@ -1325,6 +1325,7 @@ typy_iterator_dealloc (PyObject *obj)
   typy_iterator_object *iter_obj = (typy_iterator_object *) obj;
 
   Py_DECREF (iter_obj->source);
+  Py_TYPE (obj)->tp_free (obj);
 }
 
 /* Create a new Type referring to TYPE.  */
This page took 0.07426 seconds and 4 git commands to generate.