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 myrandom(void)13unsigned myrandom(void) 14 { 15 /* Simple multiply-with-carry random generator. */ 16 static unsigned m_w = 11; 17 static unsigned m_z = 13; 18 19 m_z = 36969 * (m_z & 65535) + (m_z >> 16); 20 m_w = 18000 * (m_w & 65535) + (m_w >> 16); 21 return (m_z << 16) + m_w; 22 } 23 main(int argc,char ** argv)24int main ( int argc, char** argv ) 25 { 26 int i, j, k, nbytes; 27 unsigned char* chp; 28 29 for (i = 0; i < N_TEST_ARR; i++) 30 test_arr[i] = NULL; 31 32 for (i = 0; i < N_TEST_TRANSACTIONS; i++) { 33 j = myrandom() % N_TEST_ARR; 34 if (test_arr[j]) { 35 free(test_arr[j]); 36 test_arr[j] = NULL; 37 } else { 38 nbytes = 1 + myrandom() % M_TEST_MALLOC; 39 if (myrandom()%64 == 32) 40 nbytes *= 17; 41 test_arr[j] = malloc( nbytes ); 42 chp = test_arr[j]; 43 for (k = 1; k < nbytes; k++) 44 chp[k] = (unsigned char)(k + 99); 45 } 46 } 47 48 for (i = 0; test_arr[i] == NULL; i++) ; 49 free(test_arr[i]); 50 ((char*)test_arr[i])[0] = 0; 51 52 for (i = 0; i < N_TEST_ARR; i++) { 53 if (test_arr[i]) { 54 free(test_arr[i]); 55 test_arr[i] = NULL; 56 } 57 } 58 59 return 0; 60 } 61