Memory leak in g_param_spec_flags and/or g_param_spec_enum
This showed up in GJS's Valgrind job and I can reproduce it with a trivial program.
leak.c:
#include <glib-object.h>
#include <gio/gio.h>
int main(void) {
g_type_class_unref(g_type_class_ref(G_TYPE_DBUS_CONNECTION));
return 0;
}
Trace:
$ gcc -o leak leak.c `pkg-config --cflags --libs gobject-2.0 gio-2.0`
$ valgrind --leak-check=full --suppressions=/usr/share/glib-2.0/valgrind/glib.supp ./leak
==16313== Memcheck, a memory error detector
==16313== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16313== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==16313== Command: ./leak
==16313==
==16313==
==16313== HEAP SUMMARY:
==16313== in use at exit: 44,328 bytes in 336 blocks
==16313== total heap usage: 448 allocs, 112 frees, 55,026 bytes allocated
==16313==
==16313== 24 bytes in 1 blocks are possibly lost in loss record 131 of 323
==16313== at 0x483AB1A: calloc (vg_replace_malloc.c:762)
==16313== by 0x4AC34D0: g_malloc0 (gmem.c:132)
==16313== by 0x4A47A7A: type_class_init_Wm (gtype.c:2134)
==16313== by 0x4A47A7A: g_type_class_ref (gtype.c:2950)
==16313== by 0x4A47A9B: g_type_class_ref (gtype.c:2942)
==16313== by 0x4A36897: g_param_spec_flags (gparamspecs.c:2133)
==16313== by 0x4943814: g_dbus_connection_class_init (gdbusconnection.c:875)
==16313== by 0x4943814: g_dbus_connection_class_intern_init (gdbusconnection.c:530)
==16313== by 0x4A47910: type_class_init_Wm (gtype.c:2235)
==16313== by 0x4A47910: g_type_class_ref (gtype.c:2950)
==16313== by 0x401166: main (in /path/to/leak)
==16313==
==16313== LEAK SUMMARY:
==16313== definitely lost: 0 bytes in 0 blocks
==16313== indirectly lost: 0 bytes in 0 blocks
==16313== possibly lost: 24 bytes in 1 blocks
==16313== still reachable: 22,508 bytes in 41 blocks
==16313== of which reachable via heuristic:
==16313== length64 : 104 bytes in 2 blocks
==16313== newarray : 1,568 bytes in 18 blocks
==16313== suppressed: 20,340 bytes in 283 blocks
==16313== Reachable blocks (those to which a pointer was found) are not shown.
==16313== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==16313==
==16313== For lists of detected and suppressed errors, rerun with: -s
==16313== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 21 from 21)
This happens not only with GDBusConnection but at least also with GDBusProxy. Each time g_param_spec_flags()
or g_param_spec_enum()
is involved. The class init function looks normal at first glance so it seems more likely the problem is in the param specs.