Skip to content

Commit 01b7177

Browse files
mattsu2020sylvestre
authored andcommitted
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
1 parent c1631da commit 01b7177

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/uu/sort/src/tmp_dir.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ impl Drop for TmpDirWrapper {
171171
guard.lock = None;
172172
guard.path = None;
173173
}
174+
drop(guard);
175+
176+
// Explicitly attempt cleanup before TempDir's Drop runs silently.
177+
// TempDir::drop uses `let _ = remove_dir_all()` which silently
178+
// ignores errors, potentially leaking the directory.
179+
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
180+
if let Some(ref temp_dir) = self.temp_dir {
181+
let _ = remove_tmp_dir(temp_dir.path());
182+
}
174183
}
175184
}
176185

0 commit comments

Comments
 (0)