50 lines
725 B
C
50 lines
725 B
C
|
|
#include <stdio.h>
|
||
|
|
#include <malloc.h>
|
||
|
|
|
||
|
|
size_t malloc_counter;
|
||
|
|
size_t free_counter;
|
||
|
|
|
||
|
|
void * TEST_MALLOC(size_t size)
|
||
|
|
{
|
||
|
|
printf("malloc'ed %lu\n", size);
|
||
|
|
|
||
|
|
malloc_counter += size;
|
||
|
|
return malloc(size);
|
||
|
|
}
|
||
|
|
|
||
|
|
void TEST_FREE(void *p)
|
||
|
|
{
|
||
|
|
size_t s = malloc_usable_size(p) - 8;
|
||
|
|
printf("freed %lu\n", s);
|
||
|
|
|
||
|
|
free_counter += s;
|
||
|
|
|
||
|
|
free(p);
|
||
|
|
}
|
||
|
|
|
||
|
|
#define malloc TEST_MALLOC
|
||
|
|
#define free TEST_FREE
|
||
|
|
int f(void)
|
||
|
|
{
|
||
|
|
free(malloc(16));
|
||
|
|
free(malloc(32));
|
||
|
|
free(malloc(48));
|
||
|
|
free(malloc(64));
|
||
|
|
free(malloc(96));
|
||
|
|
malloc(128);
|
||
|
|
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
#undef malloc
|
||
|
|
#undef free
|
||
|
|
|
||
|
|
int main(void)
|
||
|
|
{
|
||
|
|
malloc_counter = free_counter = 0;
|
||
|
|
(void) f();
|
||
|
|
|
||
|
|
printf("malloc: %lu, free: %lu\n", malloc_counter, free_counter);
|
||
|
|
|
||
|
|
return malloc_counter != free_counter;
|
||
|
|
}
|