Skip to content

Commit 20bc4f0

Browse files
committed
Don't leak completed generators
1 parent c8a8736 commit 20bc4f0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/generator.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,15 @@ impl<'a, Input, Output, Stack> Drop for Generator<'a, Input, Output, Stack>
234234
where Input: 'a, Output: 'a, Stack: stack::Stack {
235235
fn drop(&mut self) {
236236
unsafe {
237-
// If unwinding is not available then we have to leak the stack.
238-
if cfg!(feature = "unwind") {
239-
self.stack_ptr.map(|stack_ptr| arch::unwind(stack_ptr, self.stack.inner.base()));
240-
ptr::drop_in_place(&mut self.stack.inner);
237+
match self.stack_ptr {
238+
Some(stack_ptr) => {
239+
// If unwinding is not available then we have to leak the stack.
240+
if cfg!(feature = "unwind") {
241+
arch::unwind(stack_ptr, self.stack.inner.base());
242+
ptr::drop_in_place(&mut self.stack.inner);
243+
}
244+
}
245+
None => ptr::drop_in_place(&mut self.stack.inner)
241246
}
242247
}
243248
}

0 commit comments

Comments
 (0)