Skip to content

Commit ae20dbf

Browse files
committed
Fix fd leakage. Fix check of value returned by 'open'
1 parent b03a270 commit ae20dbf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

source/trashcan.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,10 @@ private:
335335
string timeString = currentTime.toISOExtString();
336336
string contents = format("[Trash Info]\nPath=%s\nDeletionDate=%s\n", path.escapeValue(), timeString);
337337

338-
auto mode = O_CREAT | O_WRONLY | O_EXCL;
339-
auto fd = open(toStringz(trashInfoPath), mode, octal!666);
340-
errnoEnforce(fd != 0);
338+
const mode = O_CREAT | O_WRONLY | O_EXCL;
339+
auto fd = .open(toStringz(trashInfoPath), mode, octal!666);
340+
errnoEnforce(fd != -1);
341+
scope(exit) .close(fd);
341342
errnoEnforce(write(fd, contents.ptr, contents.length) == contents.length);
342343

343344
path.rename(trashFilePath);

0 commit comments

Comments
 (0)