- leak detective is usable, but does not show static function names
[strongswan.git] / Source / testing / leak_detective_test.c
1 /**
2 * @file leak_detective_test.h
3 *
4 * @brief Tests for the leak_detective_test.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include "leak_detective_test.h"
24
25
26 void *mem_a, *mem_b, *mem_c;
27
28 void a()
29 {
30 mem_a = malloc(4);
31 }
32
33 void b()
34 {
35 a();
36 mem_b = malloc(5);
37 }
38
39 void c()
40 {
41 b();
42 mem_c = malloc(6);
43 }
44
45 void recursive(int depth)
46 {
47 void *tiny = malloc(1);
48 if (--depth > 0)
49 {
50 recursive(depth);
51 }
52 free(tiny);
53 }
54
55
56 /*
57 * described in Header-File
58 */
59 void test_leak_detective(protected_tester_t *tester)
60 {
61 void *m1, *m2, *m3;
62
63
64 m1 = malloc(1);
65 m2 = calloc(1, 2);
66 m3 = malloc(3);
67
68 m3 = realloc(m3, 4);
69
70 free(m2);
71 free(m3);
72 free(m1);
73
74 c();
75 free(mem_a);
76 free(mem_c);
77 free(mem_b);
78 recursive(10000);
79 }