mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-01-07 21:58:07 -05:00
6ce663a8bd
``` malloc_info.c: In function 'leak_memory': malloc_info.c:12:12: error: implicit declaration of function 'malloc' [-Wimplicit-function-declaration] 12 | (void)!malloc(1024 * 1024 * 1024); | ^~~~~~ malloc_info.c:10:1: note: include '<stdlib.h>' or provide a declaration of 'malloc' 9 | #include "../util.h" +++ |+#include <stdlib.h> 10 | malloc_info.c:12:12: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch] 12 | (void)!malloc(1024 * 1024 * 1024); | ^~~~~~ ``` Taken from https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/72971/ Co-authored-by: @mio
37 lines
715 B
C
37 lines
715 B
C
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#if defined(__GLIBC__) || defined(__ANDROID__)
|
|
#include <malloc.h>
|
|
#endif
|
|
|
|
#include "test_util.h"
|
|
#include "../util.h"
|
|
|
|
OPTNONE static void leak_memory(void) {
|
|
(void)!malloc(1024 * 1024 * 1024);
|
|
(void)!malloc(16);
|
|
(void)!malloc(32);
|
|
(void)!malloc(4096);
|
|
}
|
|
|
|
static void *do_work(UNUSED void *p) {
|
|
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);
|
|
}
|
|
|
|
#if defined(__GLIBC__) || defined(__ANDROID__)
|
|
malloc_info(0, stdout);
|
|
#endif
|
|
}
|