about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-05-02 17:08:04 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-05-02 17:08:04 -0400
commitcc62680cc95d2ea733dbdc03c30e5c4c48fdad04 (patch)
tree5d67f0c706152d6e1dee8457010e6022f63eea4f /src
parent4999d44d5b244671492fbdc05121416e05f729eb (diff)
downloadrust-cc62680cc95d2ea733dbdc03c30e5c4c48fdad04.tar.gz
rust-cc62680cc95d2ea733dbdc03c30e5c4c48fdad04.zip
free the borrow list propertly instead of crashing
Diffstat (limited to 'src')
-rw-r--r--src/libcore/cleanup.rs5
-rw-r--r--src/libcore/unstable/lang.rs11
2 files changed, 15 insertions, 1 deletions
diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs
index 1dfe1b22dc4..5e2f4af184d 100644
--- a/src/libcore/cleanup.rs
+++ b/src/libcore/cleanup.rs
@@ -15,6 +15,7 @@ use ptr::mut_null;
 use repr::BoxRepr;
 use sys::TypeDesc;
 use cast::transmute;
+use unstable::lang::clear_task_borrow_list;
 
 #[cfg(notest)] use ptr::to_unsafe_ptr;
 
@@ -179,6 +180,10 @@ pub unsafe fn annihilate() {
         n_bytes_freed: 0
     };
 
+    // Quick hack: we need to free this list upon task exit, and this
+    // is a convenient place to do it.
+    clear_task_borrow_list();
+
     // Pass 1: Make all boxes immortal.
     //
     // In this pass, nothing gets freed, so it does not matter whether
diff --git a/src/libcore/unstable/lang.rs b/src/libcore/unstable/lang.rs
index d25147fcde1..a3e44b5feea 100644
--- a/src/libcore/unstable/lang.rs
+++ b/src/libcore/unstable/lang.rs
@@ -91,7 +91,16 @@ fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) {
     }
 }
 
-pub fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
+pub unsafe fn clear_task_borrow_list() {
+    // pub because it is used by the box annihilator.
+    let cur_task = rust_get_task();
+    let ptr = rustrt::rust_take_task_borrow_list(cur_task);
+    if !ptr.is_null() {
+        let _: ~[BorrowRecord] = transmute(ptr);
+    }
+}
+
+fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
     debug_ptr("fail_borrowed: ", box);
 
     if !::rt::env::get().debug_borrows {