Skip to content

Commit

Permalink
avoid leaking memory after failed update
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Jun 30, 2024
1 parent d0d7e63 commit abb1600
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,14 @@ where
value: MaybeUninit::uninit(),
}));

self.update_with(update, f, true, guard)
match self.update_with(update, f, true, guard) {
Some(value) => Some(value),
None => {
// safety: we allocated this box above, and it was not inserted into the map
let _ = unsafe { Box::from_raw(update) };
None
}
}
}

// Update an entry with a remapping function.
Expand Down

0 comments on commit abb1600

Please sign in to comment.