Skip to content

Commit 4dc98e5

Browse files
committed
Make the ugly detailed leak-spray on rustc failures optional.
1 parent 4504337 commit 4dc98e5

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/rt/memory_region.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
memory_region::memory_region(rust_srv *srv, bool synchronized) :
77
_srv(srv), _parent(NULL), _live_allocations(0),
8+
_detailed_leaks(getenv("RUST_DETAILED_LEAKS") != NULL),
89
_synchronized(synchronized) {
9-
// Nop.
1010
}
1111

1212
memory_region::memory_region(memory_region *parent) :
1313
_srv(parent->_srv), _parent(parent), _live_allocations(0),
14+
_detailed_leaks(parent->_detailed_leaks),
1415
_synchronized(parent->_synchronized) {
1516
// Nop.
1617
}
@@ -83,15 +84,28 @@ memory_region::~memory_region() {
8384
}
8485
char msg[128];
8586
snprintf(msg, sizeof(msg),
86-
"leaked memory in rust main loop (%" PRIuPTR " objects)",
87-
_live_allocations);
87+
"leaked memory in rust main loop (%" PRIuPTR " objects)",
88+
_live_allocations);
8889
#ifdef TRACK_ALLOCATIONS
89-
for (size_t i = 0; i < _allocation_list.size(); i++) {
90-
if (_allocation_list[i] != NULL) {
91-
printf("allocation 0x%" PRIxPTR " was not freed\n",
92-
(uintptr_t) _allocation_list[i]);
90+
if (_detailed_leaks) {
91+
for (size_t i = 0; i < _allocation_list.size(); i++) {
92+
if (_allocation_list[i] != NULL) {
93+
printf("allocation 0x%" PRIxPTR " was not freed\n",
94+
(uintptr_t) _allocation_list[i]);
95+
}
9396
}
9497
}
9598
#endif
9699
_srv->fatal(msg, __FILE__, __LINE__, "%d objects", _live_allocations);
97100
}
101+
102+
//
103+
// Local Variables:
104+
// mode: C++
105+
// fill-column: 78;
106+
// indent-tabs-mode: nil
107+
// c-basic-offset: 4
108+
// buffer-file-coding-system: utf-8-unix
109+
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
110+
// End:
111+
//

src/rt/memory_region.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class memory_region {
1919
memory_region *_parent;
2020
size_t _live_allocations;
2121
array_list<void *> _allocation_list;
22+
const bool _detailed_leaks;
2223
const bool _synchronized;
2324
lock_and_signal _lock;
2425
public:

0 commit comments

Comments
 (0)