Skip to content

Commit 7554f5c

Browse files
committed
std: Fix a bug where Local::take() didn't zero out
In the compiled version of local_ptr (that with #[thread_local]), the take() funciton didn't zero-out the previous pointer, allowing for multiple takes (with fewer runtime assertions being tripped).
1 parent 51abdee commit 7554f5c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/libstd/rt/local_ptr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ pub mod compiled {
109109
/// Does not validate the pointer type.
110110
#[inline]
111111
pub unsafe fn take<T>() -> ~T {
112-
let ptr: ~T = cast::transmute(RT_TLS_PTR);
112+
let ptr = RT_TLS_PTR;
113+
assert!(!ptr.is_null());
114+
let ptr: ~T = cast::transmute(ptr);
113115
// can't use `as`, due to type not matching with `cfg(test)`
114116
RT_TLS_PTR = cast::transmute(0);
115117
ptr

0 commit comments

Comments
 (0)