mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-03-06 09:20:48 +01:00
[malloc-stats] Fix to not crash
Can't use constructor as malloc might be called before that.
This commit is contained in:
parent
4913f07950
commit
71c4443139
1 changed files with 9 additions and 1 deletions
|
|
@ -176,9 +176,14 @@ static void *(*old_malloc)(size_t);
|
|||
static void *(*old_realloc)(void *, size_t);
|
||||
static int enable_hook = 0;
|
||||
|
||||
static void init(void);
|
||||
|
||||
void *
|
||||
malloc(size_t size)
|
||||
{
|
||||
if (!old_malloc)
|
||||
init ();
|
||||
|
||||
if (enable_hook) {
|
||||
enable_hook = 0;
|
||||
void *caller = __builtin_return_address(0);
|
||||
|
|
@ -192,6 +197,9 @@ malloc(size_t size)
|
|||
void *
|
||||
realloc(void *ptr, size_t size)
|
||||
{
|
||||
if (!old_malloc)
|
||||
init ();
|
||||
|
||||
if (enable_hook) {
|
||||
enable_hook = 0;
|
||||
void *caller = __builtin_return_address(0);
|
||||
|
|
@ -202,7 +210,7 @@ realloc(void *ptr, size_t size)
|
|||
return old_realloc (ptr, size);
|
||||
}
|
||||
|
||||
static void __attribute__ ((constructor))
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
old_malloc = dlsym(RTLD_NEXT, "malloc");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue