Skip to content

Commit 069ce5a

Browse files
committed
Drop the closure box if Once fails
1 parent 4821b4f commit 069ce5a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,13 @@ where
136136

137137
// If the closure panicked, resume unwinding
138138
match sync_context.result.transpose() {
139-
Ok(res) => res,
139+
Ok(res) => {
140+
if res.is_none() {
141+
// if the closure didn't run (for example when using `Once`), free the box
142+
std::mem::drop(unsafe { Box::from_raw(sync_context.closure) });
143+
}
144+
res
145+
}
140146
Err(unwind_payload) => std::panic::resume_unwind(unwind_payload),
141147
}
142148
}

0 commit comments

Comments
 (0)