drd: Add a consistency check
[valgrind.git] / memcheck / tests / malloc2.c
blob44cc7bb3d6581cae240d71498836c7258190788d
2 #include <stdio.h>
3 #include <stdlib.h>
5 /* The original test driver machinery. */
6 #define N_TEST_TRANSACTIONS 500
7 #define N_TEST_ARR 2000
9 #define M_TEST_MALLOC 1000
11 void* test_arr[N_TEST_ARR];
13 int main ( int argc, char** argv )
15 int i, j, k, nbytes;
16 unsigned char* chp;
18 for (i = 0; i < N_TEST_ARR; i++)
19 test_arr[i] = NULL;
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);
37 for (i = 0; test_arr[i] == NULL; i++) ;
38 free(test_arr[i]);
39 ((char*)test_arr[i])[0] = 0;
41 for (i = 0; i < N_TEST_ARR; i++) {
42 if (test_arr[i]) {
43 free(test_arr[i]);
44 test_arr[i] = NULL;
48 return 0;