blob: d6d63882363bf7a90e2a9522106c64888ee2d567 [file] [log] [blame]
bart956801f2009-06-10 17:51:52 +00001/**
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 */
bart412efe52008-04-20 08:29:04 +00006
bart956801f2009-06-10 17:51:52 +00007#include <assert.h>
bart412efe52008-04-20 08:29:04 +00008#include <stdlib.h>
9
10int main()
11{
12 int i;
bart956801f2009-06-10 17:51:52 +000013 void* p;
14
15 for (i = 0; i < 100000; i++)
16 free(malloc(40960));
17
bart412efe52008-04-20 08:29:04 +000018 for (i = 0; i < 100000; i++)
19 {
bart956801f2009-06-10 17:51:52 +000020 p = realloc(NULL, 40960);
21 p = realloc(p, 50000);
22 p = realloc(p, 40000);
23 p = realloc(p, 0);
bartbdcf8132009-07-21 11:19:54 +000024 /*
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 */
bart3e7c4022011-03-05 14:11:40 +000029#if defined(VGO_darwin)
bartbdcf8132009-07-21 11:19:54 +000030 if (p)
31 free(p);
32#else
bart956801f2009-06-10 17:51:52 +000033 assert(! p);
bartbdcf8132009-07-21 11:19:54 +000034#endif
bart412efe52008-04-20 08:29:04 +000035 }
bart956801f2009-06-10 17:51:52 +000036
bart412efe52008-04-20 08:29:04 +000037 return 0;
38}