From ccc98ade41a697fd85d4acf38ad5ac2a66077084 Mon Sep 17 00:00:00 2001 From: mattsu Date: Sat, 18 Apr 2026 08:05:58 +0900 Subject: [PATCH] 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 --- src/uu/sort/src/tmp_dir.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/uu/sort/src/tmp_dir.rs b/src/uu/sort/src/tmp_dir.rs index 0e5bd1f34d4..81e725749bc 100644 --- a/src/uu/sort/src/tmp_dir.rs +++ b/src/uu/sort/src/tmp_dir.rs @@ -180,6 +180,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()); + } } }