Skip to content

Commit 475178f

Browse files
Handle alloc error
1 parent 2246a4e commit 475178f

File tree

1 file changed

+3
-0
lines changed
  • library/std/src/sys/thread_local

1 file changed

+3
-0
lines changed

library/std/src/sys/thread_local/os.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ impl<T: 'static> Storage<T> {
172172
// Manually allocate with the requested alignment
173173
let layout = Layout::new::<Value<T>>().align_to(align).unwrap();
174174
let ptr: *mut Value<T> = (unsafe { crate::alloc::alloc(layout) }).cast();
175+
if ptr.is_null {
176+
crate::alloc::handle_alloc_error(layout);
177+
}
175178
unsafe {
176179
ptr.write(Value {
177180
value: i.and_then(Option::take).unwrap_or_else(f),

0 commit comments

Comments
 (0)