After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 712295 - g_mem_set_vtabl() cannot be used correctly with gobject since gobject_init_ctor()
g_mem_set_vtabl() cannot be used correctly with gobject since gobject_init_ct...
Status: RESOLVED DUPLICATE of bug 701694
Product: glib
Classification: Platform
Component: gobject
2.36.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-11-14 14:09 UTC by Luc Claeys
Modified: 2013-11-15 11:26 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
program to reproduce the bug. (3.16 KB, text/plain)
2013-11-14 14:09 UTC, Luc Claeys
Details

Description Luc Claeys 2013-11-14 14:09:24 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.
Comment 1 Matthias Clasen 2013-11-15 11:26:40 UTC

*** This bug has been marked as a duplicate of bug 701694 ***