From 5af8646a8b6caf0bc71fb258225ba4f814152c1d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 14 May 2013 20:50:20 -0700 Subject: [PATCH] core: Fix leak in TLS. #6231 --- src/libcore/task/local_data_priv.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index a30db039f30d7..766815a5e90b6 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -94,12 +94,10 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { let map_ptr = rt::rust_get_task_local_data(task); if map_ptr.is_null() { let map: TaskLocalMap = @mut ~[]; + // NB: This bumps the ref count before converting to an unsafe pointer, + // keeping the map alive until TLS is destroyed rt::rust_set_task_local_data(task, cast::transmute(map)); rt::rust_task_local_data_atexit(task, cleanup_task_local_map_extern_cb); - // Also need to reference it an extra time to keep it for now. - let nonmut = cast::transmute::]>(map); - cast::bump_box_refcount(nonmut); map } else { let map = cast::transmute(map_ptr);