mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 20:54:40 +08:00
ScopeGuard: remove memory leak
Calling ScopeGuard::rollback() would leak the `on_drop` callable; this is a problem for Box<dyn FnOnce> or closures containing Drop data.
This commit is contained in:
parent
aa65856ee0
commit
b39715434b
|
@ -65,7 +65,7 @@ impl<T, F: FnOnce(&mut T)> ScopeGuard<T, F> {
|
|||
/// Cancels the unwind operation like [`ScopeGuard::cancel()`] but also returns the captured
|
||||
/// value (consuming the `ScopeGuard` in the process).
|
||||
pub fn rollback(mut guard: Self) -> T {
|
||||
let _ = guard.on_drop;
|
||||
guard.on_drop.take();
|
||||
// Safety: we're about to forget the guard altogether
|
||||
let value = unsafe { ManuallyDrop::take(&mut guard.captured) };
|
||||
std::mem::forget(guard);
|
||||
|
|
Loading…
Reference in New Issue
Block a user