8
typedef void *(*mallocer)(int n);
9
typedef void (*freeer)(void *p);
13
mallocer mallocproxy = NULL;
14
freeer freeproxy = NULL;
17
//printf("get lib\n");
18
lib_handle = dlopen("liblib.so", RTLD_NOW);
19
assert(lib_handle != NULL);
22
mallocproxy = (mallocer)dlsym(lib_handle, "mallocproxy");
23
assert(mallocproxy!= NULL);
24
freeproxy = (freeer)dlsym(lib_handle, "freeproxy");
25
assert(freeproxy!= NULL);
29
//printf("unget lib\n");
33
if (handles == 0) lib_handle = NULL;
37
int n = 0, total = 0, l = 0;
39
allocs[10] = malloc(10); // pull in real malloc
40
for (int i = 0; i < 1000; i++) {
41
//printf("%d: total ever %d MB, current MB %d, total libs %d\n", i, total, n, l);
49
if (handles > 0) unget_lib();
56
allocs[n++] = mallocproxy(1024*1024);
58
//printf("real alloc\n");
59
allocs[n++] = malloc(1024*1024);
63
//printf("real free\n");
64
free(allocs[--n]); // real free
69
if (handles > 0 && n > 0) {
73
freeproxy(allocs[--n]);
75
//printf("real free\n");
81
while (n > 0) free(allocs[--n]); // real free
82
while (handles > 0) unget_lib();
83
printf("*%d,%d*\n", total, l);