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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//------------------------------------------------------------------------------
// LG_brutal_malloc: brutal memory debugging
//------------------------------------------------------------------------------
// LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved.
// SPDX-License-Identifier: BSD-2-Clause
//
// For additional details (including references to third party source code and
// other files) see the LICENSE file or contact permission@sei.cmu.edu. See
// Contributors.txt for a full list of contributors. Created, in part, with
// funding and support from the U.S. Government (see Acknowledgments.txt file).
// DM22-0790
// Contributed by Timothy A. Davis, Texas A&M University
//------------------------------------------------------------------------------
// To enable brutal memory debugging, these four functions must be passed to
// LAGr_Init.
//------------------------------------------------------------------------------
// global variables: LG_brutal and LG_nmalloc
//------------------------------------------------------------------------------
// If LG_brutal >= 0, then that value gives the # of malloc/calloc/realloc
// calls that will succeed. Each time malloc/calloc/realloc is called, the
// LG_brutal count is decremented. Once it reaches zero, no more memory
// allocations will occur, and LG_brutal_malloc, etc, all pretend to fail
// and return NULL.
// If LG_brutal is negative, the LG_brutal_malloc/calloc/realloc functions act
// like the regular malloc/calloc/realloc functions, with no pretend failures.
// LG_nmalloc is the count of the # of allocated blocks. It is incremented by
// LG_brutal_malloc/calloc and by LG_brutal_realloc if a new block is allocated.
// It is decremented by LG_brutal_free. After LAGraph_Finalize is called,
// this value should be zero. If nonzero, a memory leak has occured.
LG_TEST_PUBLIC int64_t LG_brutal = -1 ;
LG_TEST_PUBLIC int64_t LG_nmalloc = 0 ;
//------------------------------------------------------------------------------
// LG_brutal_malloc
//------------------------------------------------------------------------------
void *LG_brutal_malloc // return pointer to allocated block of memory
//------------------------------------------------------------------------------
// LG_brutal_calloc
//------------------------------------------------------------------------------
void *LG_brutal_calloc // return pointer to allocated block of memory
//------------------------------------------------------------------------------
// LG_brutal_free
//------------------------------------------------------------------------------
void
//------------------------------------------------------------------------------
// LG_brutal_realloc
//------------------------------------------------------------------------------
void *LG_brutal_realloc // return pointer to reallocated memory