1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 /* The original test driver machinery. */
6 #define N_TEST_TRANSACTIONS 500
7 #define N_TEST_ARR 2000
8 
9 #define M_TEST_MALLOC 1000
10 
11 void* test_arr[N_TEST_ARR];
12 
main(int argc,char ** argv)13 int main ( int argc, char** argv )
14 {
15    int i, j, k, nbytes;
16    unsigned char* chp;
17 
18    for (i = 0; i < N_TEST_ARR; i++)
19       test_arr[i] = NULL;
20 
21    for (i = 0; i < N_TEST_TRANSACTIONS; i++) {
22       j = random() % N_TEST_ARR;
23       if (test_arr[j]) {
24          free(test_arr[j]);
25          test_arr[j] = NULL;
26       } else {
27          nbytes = 1 + random() % M_TEST_MALLOC;
28          if (random()%64 == 32)
29             nbytes *= 17;
30          test_arr[j] = malloc( nbytes );
31          chp = test_arr[j];
32          for (k = 1; k < nbytes; k++)
33             chp[k] = (unsigned char)(k + 99);
34       }
35    }
36 
37    for (i = 0; test_arr[i] == NULL; i++) ;
38    free(test_arr[i]);
39    ((char*)test_arr[i])[0] = 0;
40 
41    for (i = 0; i < N_TEST_ARR; i++) {
42       if (test_arr[i]) {
43          free(test_arr[i]);
44          test_arr[i] = NULL;
45       }
46    }
47 
48    return 0;
49 }
50