aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-11-30 17:10:51 -0800
committerGraydon Hoare <[email protected]>2010-11-30 17:10:51 -0800
commit4dc98e54d1191b5414e6e04367fd4e3d80311cfa (patch)
treed50353cc01e308632cb1c8938a952bb91289df67
parentTidy up structural types for rec, tup AST and typeck nodes. (diff)
downloadrust-4dc98e54d1191b5414e6e04367fd4e3d80311cfa.tar.xz
rust-4dc98e54d1191b5414e6e04367fd4e3d80311cfa.zip
Make the ugly detailed leak-spray on rustc failures optional.
-rw-r--r--src/rt/memory_region.cpp28
-rw-r--r--src/rt/memory_region.h1
2 files changed, 22 insertions, 7 deletions
diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp
index 2f841935..fb19620f 100644
--- a/src/rt/memory_region.cpp
+++ b/src/rt/memory_region.cpp
@@ -5,12 +5,13 @@
memory_region::memory_region(rust_srv *srv, bool synchronized) :
_srv(srv), _parent(NULL), _live_allocations(0),
+ _detailed_leaks(getenv("RUST_DETAILED_LEAKS") != NULL),
_synchronized(synchronized) {
- // Nop.
}
memory_region::memory_region(memory_region *parent) :
_srv(parent->_srv), _parent(parent), _live_allocations(0),
+ _detailed_leaks(parent->_detailed_leaks),
_synchronized(parent->_synchronized) {
// Nop.
}
@@ -83,15 +84,28 @@ memory_region::~memory_region() {
}
char msg[128];
snprintf(msg, sizeof(msg),
- "leaked memory in rust main loop (%" PRIuPTR " objects)",
- _live_allocations);
+ "leaked memory in rust main loop (%" PRIuPTR " objects)",
+ _live_allocations);
#ifdef TRACK_ALLOCATIONS
- for (size_t i = 0; i < _allocation_list.size(); i++) {
- if (_allocation_list[i] != NULL) {
- printf("allocation 0x%" PRIxPTR " was not freed\n",
- (uintptr_t) _allocation_list[i]);
+ if (_detailed_leaks) {
+ for (size_t i = 0; i < _allocation_list.size(); i++) {
+ if (_allocation_list[i] != NULL) {
+ printf("allocation 0x%" PRIxPTR " was not freed\n",
+ (uintptr_t) _allocation_list[i]);
+ }
}
}
#endif
_srv->fatal(msg, __FILE__, __LINE__, "%d objects", _live_allocations);
}
+
+//
+// Local Variables:
+// mode: C++
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+//
diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h
index b62f0f51..b483c602 100644
--- a/src/rt/memory_region.h
+++ b/src/rt/memory_region.h
@@ -19,6 +19,7 @@ private:
memory_region *_parent;
size_t _live_allocations;
array_list<void *> _allocation_list;
+ const bool _detailed_leaks;
const bool _synchronized;
lock_and_signal _lock;
public: