[cairo-commit] 2 commits - util/malloc-stats.c
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Dec 30 18:12:28 UTC 2022
util/malloc-stats.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
New commits:
commit 8c983c0d5d26af252dab087482ad71c8f4e35b26
Merge: 4913f0795 71c444313
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Dec 30 18:12:27 2022 +0000
Merge branch 'malloc-stats' into 'master'
[malloc-stats] Fix to not crash
See merge request cairo/cairo!378
commit 71c44431397cc4bd60a48d6787cdfd8880628223
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Thu Dec 29 19:54:51 2022 -0700
[malloc-stats] Fix to not crash
Can't use constructor as malloc might be called before that.
diff --git a/util/malloc-stats.c b/util/malloc-stats.c
index cf712bd3a..eba0b2ac0 100644
--- a/util/malloc-stats.c
+++ b/util/malloc-stats.c
@@ -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");
More information about the cairo-commit
mailing list