GTK3: deletion of Gdk.Atoms returned from Gtk.Clipboard.wait_for_targets crashes python interpreter
I'm trying to debug an issue that crashes zim (https://github.com/zim-desktop-wiki/zim-desktop-wiki) at least on macOS when pasting text (built/installed using macports) and I've come to the conclusion the error lies with pygobject. I've found that zim calls Gtk.Clipboard.wait_for_targets through pygobject and using a debugger to step through, I receive the following output when the returned targets list is freed (garbage collected or explicitly del()'ed):
DEBUG: Targets available for paste: [Gdk.Atom.intern("UTF8_STRING", False), Gdk.Atom.intern("public.utf8-plain-text", False)], we want parsetree
DEBUG: Requesting data for ('text/x-zim-parsetree', 0, 1) -- using set_with_data() workaround
Python(42098,0x1081065c0) malloc: *** error for object 0x92: pointer being freed was not allocated
Python(42098,0x1081065c0) malloc: *** set a breakpoint in malloc_error_break to debug
/opt/local/bin/zim: line 3: 42098 Abort trap: 6 XDG_DATA_DIRS=/opt/local/share:$XDG_DATA_DIRS /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/zim $@
I guess if the message is correct, there is a handler for python object deletion in pygobject which frees some memory that has not been initialized properly. Is there a good way to debug this?