From b39715434b4ff876fea088fa0e96213e1d68142a Mon Sep 17 00:00:00 2001 From: Xiretza Date: Mon, 13 Mar 2023 17:36:56 +0100 Subject: [PATCH] ScopeGuard: remove memory leak Calling ScopeGuard::rollback() would leak the `on_drop` callable; this is a problem for Box or closures containing Drop data. --- fish-rust/src/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish-rust/src/common.rs b/fish-rust/src/common.rs index 837ad6297..90d19f100 100644 --- a/fish-rust/src/common.rs +++ b/fish-rust/src/common.rs @@ -65,7 +65,7 @@ impl ScopeGuard { /// 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);