GNOME Bugzilla – Bug 694860
gtk_init_check causes memory leak on sys.argv
Last modified: 2013-10-11 06:31:53 UTC
I noticed this memory leak: G_SLICE=debug-blocks valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no python3 -c 'import sys; from gi.module import get_introspection_module; Gtk=get_introspection_module("Gtk"); Gtk.init_check(sys.argv)' ==15541== 51 bytes in 1 blocks are definitely lost in loss record 2,467 of 7,296 ==15541== at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==15541== by 0x439D12: PyUnicode_New.part.27 (unicodeobject.c:1016) ==15541== by 0x4426B9: PyUnicode_FromUnicode (unicodeobject.c:967) ==15541== by 0x4AF1A0: PySys_SetArgvEx (sysmodule.c:1801) ==15541== by 0x4BE11D: Py_Main (main.c:669) ==15541== by 0x419AF8: main (python.c:66) It doesn't generally seem to apply to inout arguments; if I don't call this with sys.argv, but instead with a custom list, this leak doesn't happen: G_SLICE=debug-blocks valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no python3 -c 'from gi.module import get_introspection_module; Gtk=get_introspection_module("Gtk"); a = ["a", "b"]; print(Gtk.init_check(a))'
I was unable to reproduce any of the noted leak with what is currently in master. This was most likely fixed with commits that has been going in for bug 693402.