GNOME Bugzilla – Bug 428726
refcount leak in pyg_flags_from_gtype
Last modified: 2007-04-30 02:27:30 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; }
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.
Thanks, this is committed to svn trunk as revision 653