2026-03-18 17:16:32 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
|
|
size_t malloc_counter;
|
|
|
|
|
size_t free_counter;
|
|
|
|
|
|
|
|
|
|
void * TEST_MALLOC(size_t size)
|
|
|
|
|
{
|
2026-03-18 18:34:02 +02:00
|
|
|
//printf("malloc'ed %lu\n", size);
|
2026-03-18 17:16:32 +02:00
|
|
|
|
|
|
|
|
malloc_counter += size;
|
|
|
|
|
return malloc(size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TEST_FREE(void *p)
|
|
|
|
|
{
|
2026-03-18 18:06:40 +02:00
|
|
|
size_t s = malloc_usable_size(p);
|
2026-03-18 18:34:02 +02:00
|
|
|
//printf("freed %lu\n", s);
|
2026-03-18 17:16:32 +02:00
|
|
|
|
|
|
|
|
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));
|
2026-03-18 18:07:22 +02:00
|
|
|
free(malloc(128));
|
2026-03-18 18:09:46 +02:00
|
|
|
free(malloc(256));
|
2026-03-18 17:16:32 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|