Skip to content

Commit cc62680

Browse files
committed
free the borrow list propertly instead of crashing
1 parent 4999d44 commit cc62680

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/libcore/cleanup.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ptr::mut_null;
1515
use repr::BoxRepr;
1616
use sys::TypeDesc;
1717
use cast::transmute;
18+
use unstable::lang::clear_task_borrow_list;
1819

1920
#[cfg(notest)] use ptr::to_unsafe_ptr;
2021

@@ -179,6 +180,10 @@ pub unsafe fn annihilate() {
179180
n_bytes_freed: 0
180181
};
181182

183+
// Quick hack: we need to free this list upon task exit, and this
184+
// is a convenient place to do it.
185+
clear_task_borrow_list();
186+
182187
// Pass 1: Make all boxes immortal.
183188
//
184189
// In this pass, nothing gets freed, so it does not matter whether

src/libcore/unstable/lang.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,16 @@ fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) {
9191
}
9292
}
9393

94-
pub fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
94+
pub unsafe fn clear_task_borrow_list() {
95+
// pub because it is used by the box annihilator.
96+
let cur_task = rust_get_task();
97+
let ptr = rustrt::rust_take_task_borrow_list(cur_task);
98+
if !ptr.is_null() {
99+
let _: ~[BorrowRecord] = transmute(ptr);
100+
}
101+
}
102+
103+
fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
95104
debug_ptr("fail_borrowed: ", box);
96105

97106
if !::rt::env::get().debug_borrows {

0 commit comments

Comments
 (0)