fix(sort): explicitly clean up temp directory in TmpDirWrapper::Drop

The `TmpDirWrapper::Drop` only cleared handler state without attempting
to delete the temporary directory. Cleanup relied entirely on the inner
`TempDir::Drop`, which silently ignores errors via `let _ =
remove_dir_all()`, potentially leaking `/tmp/uutils_sortXXXX`
directories.

Now `remove_tmp_dir` is called explicitly before `TempDir::Drop` runs,
providing a safety net for cases where the silent cleanup would fail.

Closes: #11728
This commit is contained in:
mattsu
2026-04-18 08:05:58 +09:00
committed by Sylvestre Ledru
parent c1631da43f
commit 01b7177f0b
+9
View File
@@ -171,6 +171,15 @@ impl Drop for TmpDirWrapper {
guard.lock = None;
guard.path = None;
}
drop(guard);
// Explicitly attempt cleanup before TempDir's Drop runs silently.
// TempDir::drop uses `let _ = remove_dir_all()` which silently
// ignores errors, potentially leaking the directory.
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
if let Some(ref temp_dir) = self.temp_dir {
let _ = remove_tmp_dir(temp_dir.path());
}
}
}