GNOME Bugzilla – Bug 635248
crash on accessing floating gobjects in container with transfer mode "full"
Last modified: 2010-11-30 01:21:50 UTC
I'm trying to access IBus engines from gjs. First I tried to enumerate available IBus engines: gjs> const ibus = imports.gi.IBus; gjs> ibus.init(); gjs> var bus = new ibus.Bus(); gjs> var engines = bus.list_engines(); gjs> engines.length 234 It's working so far, but if I access to an element of the list: gjs> engines[0] conflicting gtypes for prototype (null) (20631584) (was IBusEngineDesc (20574992)) Aborted (core dumped) The return value of bus.list_engines() (ibus_bus_list_engines()) is "GList *" and annotated as: @returns: (transfer full) (element-type IBusEngineDesc): A List of engines. I suspect that this is because every IBus objects are derived from GInitiallyUnowned. FWIW, pygobject2 does not crash on this case: >>> from gi.repository import IBus >>> IBus.init() >>> bus = IBus.Bus() >>> engines = bus.list_engines() >>> engines[0] <EngineDesc object at 0x7f6976ecfeb0 (IBusEngineDesc at 0x1cc90c0)> >>> engines[0].get_name() 'xkb:layout:nl'
Does list_engines() create them? If so, and they're initially unowned, they need to be (transfer none).
Thanks for the reply. Yes, list_engines() creates "initially unowned" objects, and if I change "(transfer full)" to "(transfer container)" or "(transfer none)", gjs does not crash. However, in that case who is responsible to unref/free those objects? I run: $ cat > test.js const ibus = imports.gi.IBus; ibus.init(); var bus = new ibus.Bus(); var engines = bus.list_engines(); engines[0] ^D and: $ G_SLICE=always_malloc valgrind --leak-check=full gjs < test.js I see "definitely lost" messages caused by ibus_bus_list_engines().
What will happen is that the first time GJS creates a proxy for a floating object it "adopts" the floating reference count using g_object_ref_sink(). Most likely they show up as leaked in the test above because they are never garbage collected during the run of the test. [ I think it's inappropriate for IBusObject to be "initially unowned" - it only make sense for something like GtkWidget or ClutterActor where there is a strong pattern of building a tree of objects and the parent objects act as the owners of the child objects. But as far as GJS is concerned, the memory management is fine. ]
Aha, good to know that. Thank you. Now I'm closing this as NOTABUG.