@@ -34,6 +34,14 @@ void *memory_region::get_data(alloc_header *ptr) {
34
34
return (void *)((char *)ptr + HEADER_SIZE);
35
35
}
36
36
37
+ inline void memory_region::maybe_print_backtrace (const alloc_header *header) const {
38
+ # if RUSTRT_TRACK_ALLOCATIONS >= 3
39
+ if (_detailed_leaks) {
40
+ backtrace_symbols_fd (header->bt + 1 , header->btframes - 1 , 2 );
41
+ }
42
+ # endif
43
+ }
44
+
37
45
memory_region::memory_region (bool synchronized,
38
46
bool detailed_leaks,
39
47
bool poison_on_free) :
@@ -174,13 +182,7 @@ memory_region::~memory_region() {
174
182
header->tag ,
175
183
(uintptr_t ) get_data (header));
176
184
++leak_count;
177
-
178
- # if RUSTRT_TRACK_ALLOCATIONS >= 3
179
- if (_detailed_leaks) {
180
- backtrace_symbols_fd (header->bt + 1 ,
181
- header->btframes - 1 , 2 );
182
- }
183
- # endif
185
+ maybe_print_backtrace (header);
184
186
}
185
187
}
186
188
assert (leak_count == _live_allocations);
@@ -203,9 +205,16 @@ memory_region::release_alloc(void *mem) {
203
205
204
206
# if RUSTRT_TRACK_ALLOCATIONS >= 2
205
207
if (_synchronized) { _lock.lock (); }
208
+ if (((size_t ) alloc->index ) >= _allocation_list.size ()) {
209
+ printf (" free: ptr 0x%" PRIxPTR " (%s) index %d is beyond allocation_list of size %zu\n " ,
210
+ (uintptr_t ) get_data (alloc), alloc->tag , alloc->index , _allocation_list.size ());
211
+ maybe_print_backtrace (alloc);
212
+ assert (false && " index beyond allocation_list" );
213
+ }
206
214
if (_allocation_list[alloc->index ] != alloc) {
207
215
printf (" free: ptr 0x%" PRIxPTR " (%s) is not in allocation_list\n " ,
208
216
(uintptr_t ) get_data (alloc), alloc->tag );
217
+ maybe_print_backtrace (alloc);
209
218
assert (false && " not in allocation_list" );
210
219
}
211
220
else {
0 commit comments