drd: Add a consistency check
[valgrind.git] / drd / tests / memory_allocation.c
blobd6d63882363bf7a90e2a9522106c64888ee2d567
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 */
7 #include <assert.h>
8 #include <stdlib.h>
10 int main()
12 int i;
13 void* p;
15 for (i = 0; i < 100000; i++)
16 free(malloc(40960));
18 for (i = 0; i < 100000; i++)
20 p = realloc(NULL, 40960);
21 p = realloc(p, 50000);
22 p = realloc(p, 40000);
23 p = realloc(p, 0);
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.
29 #if defined(VGO_darwin)
30 if (p)
31 free(p);
32 #else
33 assert(! p);
34 #endif
37 return 0;