mirror of
https://github.com/nimbold/Firelink.git
synced 2026-07-26 12:08:27 +00:00
fix(ytdlp): fix info.json temporary file leak using a Drop guard to ensure cleanup on all exit paths
This commit is contained in:
+10
-4
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user