Skip to content

Commit

Permalink
Don't leak completed generators
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Mar 24, 2017
1 parent c8a8736 commit 20bc4f0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,15 @@ impl<'a, Input, Output, Stack> Drop for Generator<'a, Input, Output, Stack>
where Input: 'a, Output: 'a, Stack: stack::Stack {
fn drop(&mut self) {
unsafe {
// If unwinding is not available then we have to leak the stack.
if cfg!(feature = "unwind") {
self.stack_ptr.map(|stack_ptr| arch::unwind(stack_ptr, self.stack.inner.base()));
ptr::drop_in_place(&mut self.stack.inner);
match self.stack_ptr {
Some(stack_ptr) => {
// If unwinding is not available then we have to leak the stack.
if cfg!(feature = "unwind") {
arch::unwind(stack_ptr, self.stack.inner.base());
ptr::drop_in_place(&mut self.stack.inner);
}
}
None => ptr::drop_in_place(&mut self.stack.inner)
}
}
}
Expand Down

0 comments on commit 20bc4f0

Please sign in to comment.