GNOME Bugzilla – Bug 639949
pygobject leaks references on GtkWindows
Last modified: 2011-02-04 18:13:15 UTC
We ran into a refcounting issue, so we should add some more tests for reference counting.
Created attachment 178742 [details] [review] Add tests for a GtkWindow-like sunk GInitiallyUnowned subclass The idea is that we have a GInitiallyUnowned which is owned by a library so its floating ref is already sunk. It should remain around until we ask the library to release its reference.
Created attachment 178743 [details] [review] Add tests for GtkWindow reference counting.
Created attachment 178744 [details] [review] Add tests for refcount of a GObject owned by a library When the object is constructed, its refcount is 2 because the library refs it once. It should remain around until we ask the library to release its reference.
Created attachment 178758 [details] [review] Add a test to check for regular object reference count
Created attachment 178759 [details] [review] Add tests for a GtkWindow-like sunk GInitiallyUnowned subclass The idea is that we have a GInitiallyUnowned which is owned by a library so its floating ref is already sunk. It should remain around until we ask the library to release its reference.
Created attachment 178760 [details] [review] Add tests for refcount of a GObject owned by a library When the object is constructed, its refcount is 2 because the library refs it once. It should remain around until we ask the library to release its reference.
Created attachment 178761 [details] [review] Add more reference counting tests using gobject.new()
Created attachment 178762 [details] [review] Fix reference leaks for GInitiallyUnowned objects References were leaked for GInitiallyUnowned objects which got their wrappers created several times, because someone else holds reference on it and it got out of python scope at some point.
This latest patch breaks the override test for GtkFileChooserDialog ( a crash)
Ok, the latest patch actually works with the whole test suite if you use the gi-annotations-2 branch in gtk+-3. The crash was due to a bad annotation in gtk_dialog_add_button (the return value was transfer-full instead of transfer-none) and this is fixed in the gi-annotations-2.
Created attachment 178822 [details] [review] [GI] Fix transfer annotation on gtk_dialog_add_button The transfer annotation was (transfer full) but the caller actually doesn't own a reference of the object. This made the pygobject test suite crash because pygobject was trying to unref the returned GtkButton instance.
Created attachment 178830 [details] crash reproducer With above patches applied, I get a SIGBUS crash with a lot of my pygi converted projects. For one I created a small reproducer (attached). I am currently porting system-config-printer. With the current patch [1] against git head [2] I also get a SIGBUS crash right on startup when I apply those patches, but it starts up fine with today's pygobject git trunk. I did not investigate where the crash happens yet, I'm happy to try again once the crash from test.py is fixed. [1] http://people.canonical.com/~pitti/tmp/0001-First-pass-at-converting-from-pygtk2-to-pygi-GTK3.patch [2] git://git.fedorahosted.org/git/system-config-printer.git
test.py, system-config-printer, and my ported Ubuntu projects work again if I run the gi-annotations-2 GTK branch, which fixes a lot of annotations. So it's not really the fault of above patches indeed, but this just shows that they are actually correct. :-)
Created attachment 178835 [details] [review] Add a test to check for regular object reference count
Created attachment 178836 [details] [review] Add tests for refcount of a GObject owned by a library When the object is constructed, its refcount is 2 because the library refs it once. It should remain around until we ask the library to release its reference.
Created attachment 178837 [details] [review] Fix reference leaks for GInitiallyUnowned objects References were leaked for GInitiallyUnowned objects which got their wrappers created several times, because someone else holds reference on it and it got out of python scope at some point.
Comment on attachment 178835 [details] [review] Add a test to check for regular object reference count Attachment 178835 [details] pushed as b6737b9 - Add a test to check for regular object reference count
Comment on attachment 178836 [details] [review] Add tests for refcount of a GObject owned by a library Attachment 178836 [details] pushed as cae2cf3 - Add tests for refcount of a GObject owned by a library
Attachment 178837 [details] pushed as f0a0b6c - Fix reference leaks for GInitiallyUnowned objects
For the record, this seems to break pygtk apps pretty hard: https://bugzilla.gnome.org/show_bug.cgi?id=641525