hardened_malloc/test/malloc_info.c

34 lines
641 B
C
Raw Normal View History

2019-04-30 16:54:58 -04:00
#include <pthread.h>
#include <stdio.h>
2019-04-30 16:54:58 -04:00
#include <malloc.h>
#include "test_util.h"
2022-01-04 11:56:48 -05:00
#include "../util.h"
OPTNONE static void leak_memory(void) {
(void)!malloc(1024 * 1024 * 1024);
(void)!malloc(16);
(void)!malloc(32);
(void)!malloc(4096);
2019-04-30 16:54:58 -04:00
}
2022-01-04 11:56:48 -05:00
static void *do_work(UNUSED void *p) {
2019-04-30 16:54:58 -04:00
leak_memory();
return NULL;
}
int main(void) {
pthread_t thread[4];
for (int i = 0; i < 4; i++) {
pthread_create(&thread[i], NULL, do_work, NULL);
}
for (int i = 0; i < 4; i++) {
pthread_join(thread[i], NULL);
}
2021-12-23 14:44:45 -05:00
#if defined(__GLIBC__) || defined(__ANDROID__)
2019-04-30 16:54:58 -04:00
malloc_info(0, stdout);
2021-12-23 14:44:45 -05:00
#endif
2019-04-30 16:54:58 -04:00
}