fix(ytdlp): fix info.json temporary file leak using a Drop guard to ensure cleanup on all exit paths

This commit is contained in:
NimBold
2026-06-29 10:18:17 +03:30
parent 9edf0a570b
commit f666b2e8f2
+10 -4
View File
@@ -2481,6 +2481,16 @@ pub(crate) async fn start_media_download_internal(
}
}
struct CleanupPath(Option<std::path::PathBuf>);
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) {