Skip to content

Commit cdfdd43

Browse files
committed
add calloc hook
1 parent b3d6f4d commit cdfdd43

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

hook.c

+18
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,24 @@
3030

3131
int reentrancy_guard;
3232

33+
void* (*real_calloc)(size_t nmemb, size_t size);
34+
void *calloc(size_t nmemb, size_t size) {
3335

36+
BEGIN_HOOK
37+
38+
real_calloc = dlsym(RTLD_NEXT, "calloc");
39+
void* chunk = real_calloc(nmemb, size);
40+
41+
HOOK {
42+
size_t s = malloc_usable_size(chunk);
43+
fprintf(stderr, BLUE "CALLOC(%4ld, %4ld): %p-%p (%4ld Bytes)\n" RESET, nmemb, size, chunk, chunk+s, s);
44+
}
45+
46+
END_HOOK
47+
48+
return chunk;
49+
50+
}
3451

3552
void* (*real_malloc)(size_t size);
3653
void* malloc(size_t size) {
@@ -87,3 +104,4 @@ void* realloc(void* ptr, size_t size) {
87104

88105
return chunk;
89106
}
107+

0 commit comments

Comments
 (0)