1 | #include <malloc.h> |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include <string.h> |
5 | |
6 | #define N 10000 |
7 | |
8 | static void *arr[N]; |
9 | |
10 | static int |
11 | do_test (void) |
12 | { |
13 | for (int i = 0; i < N; ++i) |
14 | { |
15 | size_t size = random () % 16384; |
16 | |
17 | if ((arr[i] = malloc (size: size)) == NULL) |
18 | { |
19 | nomem: |
20 | puts (s: "not enough memory" ); |
21 | return 0; |
22 | } |
23 | |
24 | memset (arr[i], size, size); |
25 | } |
26 | |
27 | void *p = malloc (size: 256); |
28 | if (p == NULL) |
29 | goto nomem; |
30 | memset (p, 1, 256); |
31 | |
32 | puts (s: "==================================================================" ); |
33 | |
34 | for (int i = 0; i < N; ++i) |
35 | if (i % 13 != 0) |
36 | free (ptr: arr[i]); |
37 | |
38 | puts (s: "==================================================================" ); |
39 | |
40 | malloc_trim (pad: 0); |
41 | |
42 | puts (s: "==================================================================" ); |
43 | |
44 | p = malloc (size: 30000); |
45 | if (p == NULL) |
46 | goto nomem; |
47 | |
48 | memset (p, 2, 30000); |
49 | |
50 | malloc_trim (pad: 0); |
51 | |
52 | return 0; |
53 | } |
54 | |
55 | #define TEST_FUNCTION do_test () |
56 | #include "../test-skeleton.c" |
57 | |