GNOME Bugzilla – Bug 712295
g_mem_set_vtabl() cannot be used correctly with gobject since gobject_init_ctor()
Last modified: 2013-11-15 11:26:40 UTC
Created attachment 259805 [details] program to reproduce the bug. When main() starts, it is too late to use g_mem_set_vtabl() because gobject_init_ctor() uses g_malloc(). gobject_init_ctor(), which runs before main(), uses g_quark_from_static_string() which uses g_malloc(). Therefore g_mem_set_vtabl() cannot be used in main() to install a new allocator. A call to g_free() or g_realloc() with an early allocated block returns memory to the new allocator which was allocated by the default allocator. This happens only when the gobject is linked. It is reproducible with the attached demo.c program. $ gcc -g `pkg-config --cflags glib-2.0 --libs glib-2.0 gobject-2.0` demo.c -o demo $ ./demo Using glib version 2.36 demo.c:92 Things are still all right now. demo.c:66 my_free ERROR: No sentinel. Things will go wrong now! *** Error in `./demo': free(): invalid pointer: 0x0000000000fa6db8 *** ... When linking without gobject, it works fine (the program does not use gobject). Tested on Linux Debian jessie/testing with glib version 2.36 on Intel x86_64. When using an older version of glib, e.g. 2.32 (current on debian wheezy), it works fine. Bugs 701694 and 705303 related to the profiler may be caused by this.
*** This bug has been marked as a duplicate of bug 701694 ***