Skip to content

Commit

Permalink
Fix fd leakage. Fix check of value returned by 'open'
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Mar 28, 2017
1 parent b03a270 commit ae20dbf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions source/trashcan.d
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,10 @@ private:
string timeString = currentTime.toISOExtString();
string contents = format("[Trash Info]\nPath=%s\nDeletionDate=%s\n", path.escapeValue(), timeString);

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

path.rename(trashFilePath);
Expand Down

0 comments on commit ae20dbf

Please sign in to comment.