diff options
| author | bors <bors@rust-lang.org> | 2013-07-18 22:40:38 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-07-18 22:40:38 -0700 |
| commit | 91ebfbb9592a2262c62c684a5a2431111c987b1e (patch) | |
| tree | cb97405382ae91431ac528c1527d4ebd6558c606 | |
| parent | 3514a5af0629715604c9bfde11917133b9692798 (diff) | |
| parent | 2d82d9364c194d0ee6c46c378dfdb4d8b04a581a (diff) | |
| download | rust-91ebfbb9592a2262c62c684a5a2431111c987b1e.tar.gz rust-91ebfbb9592a2262c62c684a5a2431111c987b1e.zip | |
auto merge of #7859 : kmcallister/rust/rt-diag-messages, r=pcwalton
I added these while tracking down heap corruption in Servo.
| -rw-r--r-- | src/rt/memory_region.cpp | 23 | ||||
| -rw-r--r-- | src/rt/memory_region.h | 2 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp index f3406712cb0..0d58d4dae92 100644 --- a/src/rt/memory_region.cpp +++ b/src/rt/memory_region.cpp @@ -34,6 +34,14 @@ void *memory_region::get_data(alloc_header *ptr) { return (void*)((char *)ptr + HEADER_SIZE); } +inline void memory_region::maybe_print_backtrace(const alloc_header *header) const { +# if RUSTRT_TRACK_ALLOCATIONS >= 3 + if (_detailed_leaks) { + backtrace_symbols_fd(header->bt + 1, header->btframes - 1, 2); + } +# endif +} + memory_region::memory_region(bool synchronized, bool detailed_leaks, bool poison_on_free) : @@ -174,13 +182,7 @@ memory_region::~memory_region() { header->tag, (uintptr_t) get_data(header)); ++leak_count; - -# if RUSTRT_TRACK_ALLOCATIONS >= 3 - if (_detailed_leaks) { - backtrace_symbols_fd(header->bt + 1, - header->btframes - 1, 2); - } -# endif + maybe_print_backtrace(header); } } assert(leak_count == _live_allocations); @@ -203,9 +205,16 @@ memory_region::release_alloc(void *mem) { # if RUSTRT_TRACK_ALLOCATIONS >= 2 if (_synchronized) { _lock.lock(); } + if (((size_t) alloc->index) >= _allocation_list.size()) { + printf("free: ptr 0x%" PRIxPTR " (%s) index %d is beyond allocation_list of size %zu\n", + (uintptr_t) get_data(alloc), alloc->tag, alloc->index, _allocation_list.size()); + maybe_print_backtrace(alloc); + assert(false && "index beyond allocation_list"); + } if (_allocation_list[alloc->index] != alloc) { printf("free: ptr 0x%" PRIxPTR " (%s) is not in allocation_list\n", (uintptr_t) get_data(alloc), alloc->tag); + maybe_print_backtrace(alloc); assert(false && "not in allocation_list"); } else { diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h index 4ad57c11809..b833b90d42a 100644 --- a/src/rt/memory_region.h +++ b/src/rt/memory_region.h @@ -69,6 +69,8 @@ private: void release_alloc(void *mem); void claim_alloc(void *mem); + void maybe_print_backtrace(const alloc_header *) const; + private: // private and undefined to disable copying memory_region(const memory_region& rhs); |
