After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 428726 - refcount leak in pyg_flags_from_gtype
refcount leak in pyg_flags_from_gtype
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
2.12.x
Other All
: Normal minor
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2007-04-11 18:38 UTC by Phil Dumont
Modified: 2007-04-30 02:27 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Phil Dumont 2007-04-11 18:38:08 UTC
Please describe the problem:
The call to tp_alloc() in pyg_flags_from_gtype() returns a new object with refcount 1, the reference owned by the caller.  The later Py_INCREF on the object results in a refcount leak.

Steps to reproduce:
1. 
2. 
3. 


Actual results:


Expected results:


Does this happen every time?


Other information:
--- pygobject-2.12.3/gobject/pygflags.c.orig    2007-04-11 13:30:57.000000000 -0400
+++ pygobject-2.12.3/gobject/pygflags.c 2007-04-11 13:35:45.000000000 -0400
@@ -176,7 +176,9 @@
     retval = PyDict_GetItem(values, pyint);
     Py_DECREF(pyint);

-    if (!retval) {
+    if (retval) {
+        Py_INCREF(retval);
+    } else {
        PyErr_Clear();

        retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0);
@@ -186,7 +188,6 @@
        ((PyGFlags*)retval)->gtype = gtype;
     }

-    Py_INCREF(retval);
     return retval;
 }
Comment 1 Matthew Barnes 2007-04-20 01:25:11 UTC
Confirming, as this was also reported downstream:
http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=237179

PyDict_GetItem() returns a borrowed reference, whereas tp_alloc() returns a new reference.  So you only want to INCREF the borrowed reference.
Comment 2 Johan (not receiving bugmail) Dahlin 2007-04-30 02:27:30 UTC
Thanks, this is committed to svn trunk as revision 653