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 {