1 /** 2 * @brief Repeatedly allocate and free memory. Tests whether drd really frees 3 * memory allocated by a client. See also 4 * http://bugs.kde.org/show_bug.cgi?id=161036. 5 */ 6 7 #include <assert.h> 8 #include <stdlib.h> 9 10 int main() 11 { 12 int i; 13 void* p; 14 15 for (i = 0; i < 100000; i++) 16 free(malloc(40960)); 17 18 for (i = 0; i < 100000; i++) 19 { 20 p = realloc(NULL, 40960); 21 p = realloc(p, 50000); 22 p = realloc(p, 40000); 23 p = realloc(p, 0); 24 /* 25 * glibc returns a NULL pointer when the size argument passed to realloc() 26 * is zero, while Darwin's C library returns a non-NULL pointer. Both are 27 * allowed by POSIX. 28 */ 29 #if defined(VGO_darwin) 30 if (p) 31 free(p); 32 #else 33 assert(! p); 34 #endif 35 } 36 37 return 0; 38 } 39