This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: fix refcounting bug in py-newobjfileevent.c


This fixes a bug that Kevin Pouget reported to the gdb list.

The bug is that create_new_objfile_event_object decrefs the objfile
object.  But, objfile_to_objfile_object returns a borrowed reference, so
this is incorrect.

I tried to write a robust test case for this, but couldn't.
It is reasonably easy to see the error under valgrind, though.

Tom

2012-08-28  Tom Tromey  <tromey@redhat.com>

	* python/py-newobjfileevent.c (create_new_objfile_event_object):
	Don't decref py_objfile.

diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c
index 3059ae4..46b26ab 100644
--- a/gdb/python/py-newobjfileevent.c
+++ b/gdb/python/py-newobjfileevent.c
@@ -25,23 +25,23 @@ static PyObject *
 create_new_objfile_event_object (struct objfile *objfile)
 {
   PyObject *objfile_event;
-  PyObject *py_objfile = NULL;
+  PyObject *py_objfile;
 
   objfile_event = create_event_object (&new_objfile_event_object_type);
   if (!objfile_event)
     goto fail;
 
+  /* Note that objfile_to_objfile_object returns a borrowed reference,
+     so we don't need a decref here.  */
   py_objfile = objfile_to_objfile_object (objfile);
   if (!py_objfile || evpy_add_attribute (objfile_event,
                                          "new_objfile",
                                          py_objfile) < 0)
     goto fail;
-  Py_DECREF (py_objfile);
 
   return objfile_event;
 
  fail:
-  Py_XDECREF (py_objfile);
   Py_XDECREF (objfile_event);
   return NULL;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]