Debian Codegraph @

gc/tests/leak_test.c

raw
1
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #include "leak_detector.h"
6
7 #define CHECK_OUT_OF_MEMORY(p) \
8 do { \
9 if (NULL == (p)) { \
10 fprintf(stderr, "Out of memory\n"); \
11 exit(69); \
12 } \
13 } while (0)
14
15 int main(void) {
16 char *p[10];
17 int i;
18 GC_set_find_leak(1); /* for new collect versions not compiled */
19 /* with -DFIND_LEAK. */
20
21 GC_INIT(); /* Needed if thread-local allocation is enabled. */
22 /* FIXME: This is not ideal. */
23 for (i = 0; i < 10; ++i) {
24 p[i] = (char*)malloc(sizeof(int)+i);
25 CHECK_OUT_OF_MEMORY(p[i]);
26 (void)malloc_usable_size(p[i]);
27 }
28 CHECK_LEAKS();
29 for (i = 1; i < 10; ++i) {
30 free(p[i]);
31 }
32 for (i = 0; i < 9; ++i) {
33 p[i] = (char*)malloc(sizeof(int)+i);
34 CHECK_OUT_OF_MEMORY(p[i]);
35 }
36 CHECK_LEAKS();
37 CHECK_LEAKS();
38 CHECK_LEAKS();
39 return 0;
40 }