Skip to content

Commit dfa5595

Browse files
author
Keegan McAllister
committed
rt: Diagnose bad alloc index in release_alloc with RUSTRT_TRACK_ALLOCATIONS
1 parent 060de10 commit dfa5595

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/rt/memory_region.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ memory_region::release_alloc(void *mem) {
203203

204204
# if RUSTRT_TRACK_ALLOCATIONS >= 2
205205
if (_synchronized) { _lock.lock(); }
206+
if (((size_t) alloc->index) >= _allocation_list.size()) {
207+
printf("free: ptr 0x%" PRIxPTR " (%s) index %d is beyond allocation_list of size %zu\n",
208+
(uintptr_t) get_data(alloc), alloc->tag, alloc->index, _allocation_list.size());
209+
assert(false && "index beyond allocation_list");
210+
}
206211
if (_allocation_list[alloc->index] != alloc) {
207212
printf("free: ptr 0x%" PRIxPTR " (%s) is not in allocation_list\n",
208213
(uintptr_t) get_data(alloc), alloc->tag);

0 commit comments

Comments
 (0)