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
111
112
113
114
115
|
/*
Unix SMB/CIFS implementation.
local testing of talloc routines.
Copyright (C) Andrew Tridgell 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
/*
test references
*/
static BOOL test_ref1(void)
{
void *p1, *p2, *ref, *r1;
printf("TESTING SINGLE REFERENCE FREE\n");
p1 = talloc_named_const(NULL, 1, "p1");
p2 = talloc_named_const(p1, 1, "p2");
talloc_named_const(p1, 1, "x1");
talloc_named_const(p1, 1, "x2");
talloc_named_const(p1, 1, "x3");
r1 = talloc_named_const(NULL, 1, "r1");
ref = talloc_reference(r1, p2);
talloc_report_full(NULL, stdout);
printf("Freeing p2\n");
talloc_free(p2);
talloc_report_full(NULL, stdout);
printf("Freeing p1\n");
talloc_free(p1);
talloc_report_full(NULL, stdout);
printf("Freeing r1\n");
talloc_free(r1);
talloc_report_full(NULL, stdout);
if (talloc_total_size(NULL) != 0) {
printf("non-zero total size\n");
return False;
}
return True;
}
/*
test references
*/
static BOOL test_ref2(void)
{
void *p1, *p2, *ref, *r1;
printf("TESTING DOUBLE REFERENCE FREE\n");
p1 = talloc_named_const(NULL, 1, "p1");
talloc_named_const(p1, 1, "x1");
talloc_named_const(p1, 1, "x2");
talloc_named_const(p1, 1, "x3");
p2 = talloc_named_const(p1, 1, "p2");
r1 = talloc_named_const(NULL, 1, "r1");
ref = talloc_reference(r1, p2);
talloc_report_full(NULL, stdout);
printf("Freeing ref\n");
talloc_free(ref);
talloc_report_full(NULL, stdout);
printf("Freeing p2\n");
talloc_free(p2);
talloc_report_full(NULL, stdout);
printf("Freeing p1\n");
talloc_free(p1);
talloc_report_full(NULL, stdout);
printf("Freeing r1\n");
talloc_free(r1);
talloc_report_full(NULL, stdout);
if (talloc_total_size(NULL) != 0) {
printf("non-zero total size\n");
return False;
}
return True;
}
BOOL torture_local_talloc(int dummy)
{
BOOL ret = True;
init_iconv();
ret &= test_ref1();
ret &= test_ref2();
return True;
}
|