Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid leaking directory list handles on Windows #375

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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