Skip to content

Commit

Permalink
free the borrow list propertly instead of crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed May 2, 2013
1 parent 4999d44 commit cc62680
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/libcore/unstable/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cc62680

Please sign in to comment.