summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/malloc-stats.c22
1 files changed, 22 insertions, 0 deletions
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;
@@ -195,6 +196,22 @@ malloc(size_t 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)
{
if (!old_malloc)
@@ -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());