Skip to content

Commit

Permalink
Merge pull request #2462 from Skgland/fix-segfault
Browse files Browse the repository at this point in the history
fix segfault by dropping loader state payload after resetting machine
  • Loading branch information
mthom authored Aug 3, 2024
2 parents 5038b71 + 9e8d8aa commit 4ce4cd1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,10 @@ impl<T: ?Sized + ArenaAllocated> TypedArenaPtr<T> {

impl<P, T: ?Sized + ArenaAllocated<Payload = ManuallyDrop<P>>> TypedArenaPtr<T> {
pub fn drop_payload(&mut self) {
self.set_tag(ArenaHeaderTag::Dropped);
unsafe { ManuallyDrop::drop(&mut *self.as_ptr()) }
if self.get_tag() != ArenaHeaderTag::Dropped {
self.set_tag(ArenaHeaderTag::Dropped);
unsafe { ManuallyDrop::drop(&mut *self.as_ptr()) }
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/machine/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ impl<'a> LoadState<'a> for LiveLoadAndMachineState<'a> {
#[inline(always)]
fn reset_machine(loader: &mut Loader<'a, Self>) {
if loader.payload.load_state.get_tag() != ArenaHeaderTag::Dropped {
loader.payload.load_state.drop_payload();
loader.reset_machine();
loader.payload.load_state.drop_payload();
}
}

Expand Down

0 comments on commit 4ce4cd1

Please sign in to comment.