GNOME Bugzilla – Bug 730138
gst_bin_add introspection annatation error leads to python resource leak
Last modified: 2017-05-11 10:13:21 UTC
Created attachment 276542 [details] test script Using python bindings any element added to a GstBin will be leaked when the bin is disposed of. It appears that the element is not (transfer full) but should be (transfer none). This error leads to the pygobject code adding an extra ref to the element that stops it being disposed of. The attached gst_test.py demonstrates the problem. It pauses to allow you to look at the /proc/xxx/fd to see how many fd's have been opened. $ python gst_test.py init done [At this point only 3 fds] e1 <__main__.GstAlsaSink object at 0x133f320 (GstAlsaSink at 0x14cc850)> [At this point only 5 fds, a socketpair accounts for extra 2] e1 added to b <__main__.GstAlsaSink object at 0x133f320 (GstAlsaSink at 0x14cc850)> <Bin object at 0x133f2d0 (GstBin at 0x1548030)> b None e1 None [At this point only 5 fds, but it should be 3 the socketpair has not been close as the alsasink has not been disposed of]
Created attachment 276543 [details] [review] patch to fix annatation problem The attached patch fixes the problem.
Review of attachment 276543 [details] [review]: gst_bin_add is not transfer-none, it indeed takes the reference from the application as it does a g_object_ref_sink on the passed element if it doesn't have a parent yet. What I think you see on your case is that python bindings actually pass a ref and keep a ref on your variable instead of transforming it to None. If you print e1 after adding it to the bin you will still see that your variable holds a ref to it. Are you looking at this for any particular reason? Are you having an issue with refcounts?
Wait, just found what you mean, after setting e1 to None it still has those fds open. Will check with gir folks, but it is not a transfer-none, should be either transfer-full or transfer-floating.
I'm sure there's a bug about this somewhere already
bug #657202
The other bug has been hanging around for almost 3 years and is not fixed. transfer-floating is documented as behaving the same as transfer-none. If gst_bin_add needs to be transfer-full then the bug is in the pygobject code that adds an additional ref if the argument is transfer-full presumably.
Created attachment 276663 [details] [review] patch to fix annatation problem v2 Changed the patch to use transfer floating as suggested.
"transfer floating" *sounds* right if it's supposed to mean that only objects with a floating ref are transfered and others not. This is not how it's described in https://wiki.gnome.org/Projects/GObjectIntrospection/Annotations however. If that's what it means, then the semantics should be described as such. (The fact that it's equivalent to 'none' because bindings do this or that with floating refs is not relevant and shouldn't be relied on in the annotation description IMHO). So we should wait for someone to clarify that in the wiki before putting this in IMHO.
Let's handle that in bug #702960, it's all the same problem. *** This bug has been marked as a duplicate of bug 702960 ***