Skip to content

Commit

Permalink
Fixed memory leak after force unwind (#53)
Browse files Browse the repository at this point in the history
Fixes a memory leak when force unwinding.
  • Loading branch information
zonyitoo authored and lhecker committed May 1, 2016
1 parent 515d051 commit 64e1334
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,20 @@ impl DerefMut for Handle {
impl Drop for Handle {
#[inline]
fn drop(&mut self) {
let ctx = self.take_context();
let mut ctx = self.take_context();
let state = self.state();

trace!("{:?}: dropping with state {:?}", self, state);
self.state = State::Dropping;

if state == State::Finished {
ctx.resume(0);
} else {
ctx.resume_ontop(self.0 as *mut _ as usize, coroutine_unwind);
if state != State::Finished {
ctx = ctx.resume_ontop(self.0 as *mut _ as usize, coroutine_unwind).context;
}

debug_assert!(self.state() == State::Finished,
"Expecting Coroutine to be finished");

// Final step, drop the coroutine
self.state = State::Dropping;
ctx.resume(0);
}
}

Expand Down

0 comments on commit 64e1334

Please sign in to comment.