From 60216294d7203c774240eae47e7b794ad3c2963b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 19 Dec 2023 12:26:51 +0100 Subject: [PATCH] Avoid leaking directory list handles on Windows. --- source/vibe/core/file.d | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 4b6887ad..5e9fb8ee 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -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); @@ -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))