[cairo-commit] 2 commits - util/malloc-stats.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 27 20:50:33 UTC 2023


 util/malloc-stats.c |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

New commits:
commit ffabca7924ac57cb808a6a05fa1b00e038f068b5
Merge: 407bb0a47 25b6775cc
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Jan 27 20:50:31 2023 +0000

    Merge branch 'calloc' into 'master'
    
    [malloc-stats] Measure calloc
    
    See merge request cairo/cairo!429

commit 25b6775cc6eef8deea8c06b83a131c362efd8979
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Jan 26 14:20:12 2023 -0700

    [malloc-stats] Measure calloc

diff --git a/util/malloc-stats.c b/util/malloc-stats.c
index eba0b2ac0..a086b0543 100644
--- a/util/malloc-stats.c
+++ b/util/malloc-stats.c
@@ -173,6 +173,7 @@ func_stats_add (const void *caller, int is_realloc, size_t size)
 #include <dlfcn.h>
 
 static void *(*old_malloc)(size_t);
+static void *(*old_calloc)(size_t, size_t);
 static void *(*old_realloc)(void *, size_t);
 static int enable_hook = 0;
 
@@ -194,6 +195,22 @@ malloc(size_t size)
     return old_malloc (size);
 }
 
+void *
+calloc(size_t nmemb, size_t size)
+{
+    if (!old_calloc)
+      init ();
+
+    if (enable_hook) {
+	enable_hook = 0;
+	void *caller = __builtin_return_address(0);
+	func_stats_add (caller, 0, nmemb * size);
+	enable_hook = 1;
+    }
+
+    return old_calloc (nmemb, size);
+}
+
 void *
 realloc(void *ptr, size_t size)
 {
@@ -218,6 +235,11 @@ init(void)
 	fprintf(stderr, "%s\n", dlerror());
 	exit(1);
     }
+    old_calloc = dlsym(RTLD_NEXT, "calloc");
+    if (!old_calloc) {
+	fprintf(stderr, "%s\n", dlerror());
+	exit(1);
+    }
     old_realloc = dlsym(RTLD_NEXT, "realloc");
     if (!old_realloc) {
 	fprintf(stderr, "%s\n", dlerror());


More information about the cairo-commit mailing list