GNOME Bugzilla – Bug 681913
gst_init_check cause memory leak
Last modified: 2012-08-15 14:33:16 UTC
Steps to Reproduce: when using the hello world application with the minor change: gst_init(&argc, &argv) -> gst_init_check(&argc, &argv, &err) I recieve in valgrind the following error: ==19907== 8,192 bytes in 1 blocks are definitely lost in loss record 4,381 of 4,501 ==19907== at 0x4028308: malloc (vg_replace_malloc.c:263) ==19907== by 0x43C73AA: ??? (in /lib/i386-linux-gnu/libglib-2.0.so.0.3200.3) ==19907== by 0x43C7722: g_malloc (in /lib/i386-linux-gnu/libglib-2.0.so.0.3200.3) ==19907== by 0x43C79CA: g_malloc_n (in /lib/i386-linux-gnu/libglib-2.0.so.0.3200.3) ==19907== by 0x43A5D4F: g_quark_from_static_string (in /lib/i386-linux-gnu/libglib-2.0.so.0.3200.3) ==19907== by 0x41FE7A3: g_type_init_with_debug_flags (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.3200.3) ==19907== by 0x41FE97A: g_type_init (in /usr/lib/i386-linux-gnu/libgobject-2.0.so.0.3200.3) ==19907== by 0x40FC810: gst_init_check (in /usr/lib/i386-linux-gnu/libgstreamer-0.10.so.0.30.0) ==19907== by 0x448CE45: (below main) (libc-start.c:228) I checked the issue only on Debian Linux 2.6.39-4, gstreamer-0.10.36
Please sudo apt-get install libc6-dbg libglib2.0-0-dbg libgstreamer0.10-0-dbg to get more useful output from valgrind. However, I suspect it's not actually a leak, but a global one-time allocation of the type system.
After installation, this is the output from valgrind: 8,192 bytes in 1 blocks are definitely lost in loss record 3,072 of 3,162 ==24518== at 0x4028308: malloc (vg_replace_malloc.c:263) ==24518== by 0x409E3AA: standard_malloc (gmem.c:85) ==24518== by 0x409E722: g_malloc (gmem.c:159) ==24518== by 0x409E9CA: g_malloc_n (gmem.c:361) ==24518== by 0x407CD4F: g_quark_from_static_string (gdataset.c:1281) ==24518== by 0x44237A3: g_type_init_with_debug_flags (gtype.c:4305) ==24518== by 0x442397A: g_type_init (gtype.c:4388) ==24518== by 0x4321810: gst_init_check (in /usr/lib/i386-linux-gnu/libgstreamer-0.10.so.0.30.0) ==24518== by 0x445DE45: (below main) (libc-start.c:228) It is a one-time allocation since the call to gst_init_check is done only once.
This appears to be an intentional leak inside GLib. /* HOLDS: g_quark_global_lock */ static inline GQuark g_quark_new (gchar *string) { GQuark quark; gchar **g_quarks_new; if (g_quark_seq_id % G_QUARK_BLOCK_SIZE == 0) { g_quarks_new = g_new (gchar*, g_quark_seq_id + G_QUARK_BLOCK_SIZE); if (g_quark_seq_id != 0) memcpy (g_quarks_new, g_quarks, sizeof (char *) * g_quark_seq_id); memset (g_quarks_new + g_quark_seq_id, 0, sizeof (char *) * G_QUARK_BLOCK_SIZE); /* This leaks the old quarks array. Its unfortunate, but it allows us to do lockless lookup of the arrays, and there shouldn't be that many quarks in an app */ g_atomic_pointer_set (&g_quarks, g_quarks_new); } if (!g_quark_ht) { g_assert (g_quark_seq_id == 0); g_quark_ht = g_hash_table_new (g_str_hash, g_str_equal); g_quarks[g_quark_seq_id] = NULL; g_atomic_int_inc (&g_quark_seq_id); } quark = g_quark_seq_id; g_atomic_pointer_set (&g_quarks[quark], string); g_hash_table_insert (g_quark_ht, string, GUINT_TO_POINTER (quark)); g_atomic_int_inc (&g_quark_seq_id); return quark; } Feel free to move this to GLib and re-open it, but it does look intentional..