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 639949 - pygobject leaks references on GtkWindows
pygobject leaks references on GtkWindows
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-19 14:14 UTC by Steve Frécinaux
Modified: 2011-02-04 18:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add tests for a GtkWindow-like sunk GInitiallyUnowned subclass (7.78 KB, patch)
2011-01-19 15:59 UTC, Steve Frécinaux
none Details | Review
Add tests for GtkWindow reference counting. (2.95 KB, patch)
2011-01-19 16:00 UTC, Steve Frécinaux
none Details | Review
Add tests for refcount of a GObject owned by a library (7.60 KB, patch)
2011-01-19 16:00 UTC, Steve Frécinaux
none Details | Review
Add a test to check for regular object reference count (1.14 KB, patch)
2011-01-19 17:49 UTC, Steve Frécinaux
none Details | Review
Add tests for a GtkWindow-like sunk GInitiallyUnowned subclass (10.48 KB, patch)
2011-01-19 17:49 UTC, Steve Frécinaux
none Details | Review
Add tests for refcount of a GObject owned by a library (7.77 KB, patch)
2011-01-19 17:50 UTC, Steve Frécinaux
none Details | Review
Add more reference counting tests using gobject.new() (3.91 KB, patch)
2011-01-19 17:50 UTC, Steve Frécinaux
none Details | Review
Fix reference leaks for GInitiallyUnowned objects (2.62 KB, patch)
2011-01-19 17:50 UTC, Steve Frécinaux
none Details | Review
[GI] Fix transfer annotation on gtk_dialog_add_button (1.09 KB, patch)
2011-01-20 10:55 UTC, Steve Frécinaux
committed Details | Review
crash reproducer (300 bytes, text/x-python)
2011-01-20 11:53 UTC, Martin Pitt
  Details
Add a test to check for regular object reference count (1.14 KB, patch)
2011-01-20 13:15 UTC, Steve Frécinaux
committed Details | Review
Add tests for refcount of a GObject owned by a library (8.95 KB, patch)
2011-01-20 13:17 UTC, Steve Frécinaux
committed Details | Review
Fix reference leaks for GInitiallyUnowned objects (11.51 KB, patch)
2011-01-20 13:18 UTC, Steve Frécinaux
committed Details | Review

Description Steve Frécinaux 2011-01-19 14:14:06 UTC
We ran into a refcounting issue, so we should add some more tests for reference counting.
Comment 1 Steve Frécinaux 2011-01-19 15:59:59 UTC
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.
Comment 2 Steve Frécinaux 2011-01-19 16:00:03 UTC
Created attachment 178743 [details] [review]
Add tests for GtkWindow reference counting.
Comment 3 Steve Frécinaux 2011-01-19 16:00:06 UTC
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.
Comment 4 Steve Frécinaux 2011-01-19 17:49:01 UTC
Created attachment 178758 [details] [review]
Add a test to check for regular object reference count
Comment 5 Steve Frécinaux 2011-01-19 17:49:26 UTC
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.
Comment 6 Steve Frécinaux 2011-01-19 17:50:01 UTC
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.
Comment 7 Steve Frécinaux 2011-01-19 17:50:27 UTC
Created attachment 178761 [details] [review]
Add more reference counting tests using gobject.new()
Comment 8 Steve Frécinaux 2011-01-19 17:50:49 UTC
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.
Comment 9 Steve Frécinaux 2011-01-19 18:13:24 UTC
This latest patch breaks the override test for GtkFileChooserDialog ( a crash)
Comment 10 Steve Frécinaux 2011-01-20 10:10:14 UTC
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.
Comment 11 Steve Frécinaux 2011-01-20 10:55:30 UTC
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.
Comment 12 Martin Pitt 2011-01-20 11:53:20 UTC
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
Comment 13 Martin Pitt 2011-01-20 12:07:21 UTC
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. :-)
Comment 14 Steve Frécinaux 2011-01-20 13:15:50 UTC
Created attachment 178835 [details] [review]
Add a test to check for regular object reference count
Comment 15 Steve Frécinaux 2011-01-20 13:17:48 UTC
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.
Comment 16 Steve Frécinaux 2011-01-20 13:18:03 UTC
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 17 Tomeu Vizoso 2011-01-20 13:47:11 UTC
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 18 Tomeu Vizoso 2011-01-20 13:52:09 UTC
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
Comment 19 Tomeu Vizoso 2011-01-20 14:21:12 UTC
Attachment 178837 [details] pushed as f0a0b6c - Fix reference leaks for GInitiallyUnowned objects
Comment 20 Martin Pitt 2011-02-04 18:13:15 UTC
For the record, this seems to break pygtk apps pretty hard:

https://bugzilla.gnome.org/show_bug.cgi?id=641525