Skip to content

Commit

Permalink
Avoid leaking directory list handles on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Dec 19, 2023
1 parent ee9870c commit 6021629
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions source/vibe/core/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,13 @@ void listDirectory(NativePath path, DirectoryListMode mode,
ioWorkerTaskPool.runTask(&performListDirectory, () @trusted { return req; } ());

ListDirectoryData itm;

scope (exit) {
// makes sure that the directory handle is closed before returning
req.channel.close();
while (!req.channel.empty) req.channel.tryConsumeOne(itm);
}

while (req.channel.tryConsumeOne(itm)) {
if (itm.error.length)
throw new Exception(itm.error);
Expand Down Expand Up @@ -1068,6 +1075,7 @@ private void performListDirectory(ListDirectoryRequest req)
null, 2/*FIND_FIRST_EX_LARGE_FETCH*/);
wenforce(fh != INVALID_HANDLE_VALUE, path.toString);
scope (exit) FindClose(fh);

do {
// skip non-directories if requested
if (dirs_only && !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
Expand Down

0 comments on commit 6021629

Please sign in to comment.