common_check.c revision b1798ddcfb952efb7cc8bacaf51b3486a7fec121
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher Common utilities for check-based tests using talloc.
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher Martin Nagy <mnagy@redhat.com>
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher Copyright (C) Red Hat, Inc 2009
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher This program is free software; you can redistribute it and/or modify
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher it under the terms of the GNU General Public License as published by
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher (at your option) any later version.
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher This program is distributed in the hope that it will be useful,
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher GNU General Public License for more details.
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher You should have received a copy of the GNU General Public License
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagherstatic struct size_snapshot *snapshot_stack;
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher_check_leaks(TALLOC_CTX *ctx, size_t bytes, const char *location)
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher fprintf(stderr, "Leak report for %s:\n", location);
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher fail("%s: memory leaks detected, %d bytes still allocated",
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher snapshot = talloc(NULL, struct size_snapshot);
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher snapshot->bytes_allocated = talloc_total_size(ctx);
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher_check_leaks_pop(TALLOC_CTX *ctx, const char *location)
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher bytes_allocated = snapshot->bytes_allocated;
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher fail_if(old_ctx != ctx, "Bad push/pop order");
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher _check_leaks(old_ctx, bytes_allocated, location);
b1798ddcfb952efb7cc8bacaf51b3486a7fec121Stephen Gallagher fail_unless(global_talloc_context != NULL, "talloc_new failed");