1 #include <stdlib.h>
2 /* To be run with --freelist-vol=1000000 --freelist-big-blocks=50000 */
jumped(void)3 static void jumped(void)
4 {
5    ;
6 }
main(int argc,char * argv[])7 int main(int argc, char *argv[])
8 {
9    char *semi_big = NULL;
10    char *big = NULL;
11    char *small = NULL;
12    char *other_small = NULL;
13    int i;
14    int j;
15 
16    /* Verify that access via a dangling pointer to a big block bigger than
17       the free list is found by memcheck (still on the free list). */
18    semi_big = malloc (900000);
19    big = malloc (1000015);
20    free(semi_big);
21    free(big);
22    if (big[1000] > 0x0) jumped();
23    if (semi_big[1000] > 0x0) jumped();
24 
25    /* Then verify that dangling pointers for small blocks is not hampered
26       by doing big alloc/free. */
27    small = malloc (10000);
28    free(small);
29 
30    /* We should still have a nice error msg for the semi_big
31       but not for the big block, which has been removed from the free list
32       with the malloc of small above. */
33    if (big[2000] > 0x0) jumped();
34    if (semi_big[2000] > 0x0) jumped();
35 
36    big = NULL;
37 
38    {
39       big = malloc (1000015);
40       free(big);
41       if (small[10] > 0x0) jumped();
42 
43       /* Do not common up the below in a loop. We
44          want a different error/stack trace for each of
45          these. */
46       if (big[10] > 0x0) jumped();
47    }
48 
49 
50    for (i = 0; i < 100; i++) {
51       other_small = malloc(10000);
52       for (j = 0; j < 10000; j++)
53          other_small[j] = 0x1;
54    }
55    if (small[10] > 0x0) jumped();
56    return 0;
57 }
58