From f666b2e8f22aaf7a123d68975e20f2cd24004cc4 Mon Sep 17 00:00:00 2001 From: NimBold Date: Mon, 29 Jun 2026 10:18:17 +0330 Subject: [PATCH] fix(ytdlp): fix info.json temporary file leak using a Drop guard to ensure cleanup on all exit paths --- src-tauri/src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5a03245..d35cb66 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -2481,6 +2481,16 @@ pub(crate) async fn start_media_download_internal( } } + struct CleanupPath(Option); + impl Drop for CleanupPath { + fn drop(&mut self) { + if let Some(path) = self.0.take() { + let _ = std::fs::remove_file(path); + } + } + } + let _cleanup = CleanupPath(temp_info_path.clone()); + if let Some(path) = temp_info_path.as_ref() { cmd = cmd.arg("--load-info-json").arg(path); } else { @@ -2631,10 +2641,6 @@ pub(crate) async fn start_media_download_internal( } }; - if let Some(path) = temp_info_path { - let _ = std::fs::remove_file(path); - } - let transient = is_transient_network_error(&failure_reason); let strikes_left = strike < MAX_RETRIES; if !(transient && strikes_left) {