]>
Commit | Line | Data |
---|---|---|
1 | #define JEMALLOC_MANGLE | |
2 | #include "jemalloc_test.h" | |
3 | ||
4 | int | |
5 | main(void) | |
6 | { | |
7 | int ret, err; | |
8 | size_t sz, lg_chunk, chunksize, i; | |
9 | char *p, *q; | |
10 | ||
11 | malloc_printf("Test begin\n"); | |
12 | ||
13 | sz = sizeof(lg_chunk); | |
14 | if ((err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0))) { | |
15 | assert(err != ENOENT); | |
16 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, | |
17 | strerror(err)); | |
18 | ret = 1; | |
19 | goto label_return; | |
20 | } | |
21 | chunksize = ((size_t)1U) << lg_chunk; | |
22 | ||
23 | p = (char *)malloc(chunksize); | |
24 | if (p == NULL) { | |
25 | malloc_printf("malloc(%zu) --> %p\n", chunksize, p); | |
26 | ret = 1; | |
27 | goto label_return; | |
28 | } | |
29 | memset(p, 'a', chunksize); | |
30 | ||
31 | q = (char *)realloc(p, chunksize * 2); | |
32 | if (q == NULL) { | |
33 | malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize * 2, | |
34 | q); | |
35 | ret = 1; | |
36 | goto label_return; | |
37 | } | |
38 | for (i = 0; i < chunksize; i++) { | |
39 | assert(q[i] == 'a'); | |
40 | } | |
41 | ||
42 | p = q; | |
43 | ||
44 | q = (char *)realloc(p, chunksize); | |
45 | if (q == NULL) { | |
46 | malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize, q); | |
47 | ret = 1; | |
48 | goto label_return; | |
49 | } | |
50 | for (i = 0; i < chunksize; i++) { | |
51 | assert(q[i] == 'a'); | |
52 | } | |
53 | ||
54 | free(q); | |
55 | ||
56 | ret = 0; | |
57 | label_return: | |
58 | malloc_printf("Test end\n"); | |
59 | return (ret); | |
60 | } |