bart | 956801f | 2009-06-10 17:51:52 +0000 | [diff] [blame] | 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 | */ | ||||
bart | 412efe5 | 2008-04-20 08:29:04 +0000 | [diff] [blame] | 6 | |
bart | 956801f | 2009-06-10 17:51:52 +0000 | [diff] [blame] | 7 | #include <assert.h> |
bart | 412efe5 | 2008-04-20 08:29:04 +0000 | [diff] [blame] | 8 | #include <stdlib.h> |
9 | |||||
10 | int main() | ||||
11 | { | ||||
12 | int i; | ||||
bart | 956801f | 2009-06-10 17:51:52 +0000 | [diff] [blame] | 13 | void* p; |
14 | |||||
15 | for (i = 0; i < 100000; i++) | ||||
16 | free(malloc(40960)); | ||||
17 | |||||
bart | 412efe5 | 2008-04-20 08:29:04 +0000 | [diff] [blame] | 18 | for (i = 0; i < 100000; i++) |
19 | { | ||||
bart | 956801f | 2009-06-10 17:51:52 +0000 | [diff] [blame] | 20 | p = realloc(NULL, 40960); |
21 | p = realloc(p, 50000); | ||||
22 | p = realloc(p, 40000); | ||||
23 | p = realloc(p, 0); | ||||
bart | bdcf813 | 2009-07-21 11:19:54 +0000 | [diff] [blame] | 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(__APPLE__) | ||||
30 | if (p) | ||||
31 | free(p); | ||||
32 | #else | ||||
bart | 956801f | 2009-06-10 17:51:52 +0000 | [diff] [blame] | 33 | assert(! p); |
bart | bdcf813 | 2009-07-21 11:19:54 +0000 | [diff] [blame] | 34 | #endif |
bart | 412efe5 | 2008-04-20 08:29:04 +0000 | [diff] [blame] | 35 | } |
bart | 956801f | 2009-06-10 17:51:52 +0000 | [diff] [blame] | 36 | |
bart | 412efe5 | 2008-04-20 08:29:04 +0000 | [diff] [blame] | 37 | return 0; |
38 | } |