From 83a01c27a2d2294137d48912c7600c59102b9c66 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 23 Jun 2020 06:13:51 -0400 Subject: [PATCH] file_system: Prevent resource leaks in DeleteDirectory() We need to remember to close the search handle in the error cases. --- src/common/file_system.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index ecdb9a90b..a0b08f823 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -1027,13 +1027,19 @@ bool FileSystem::DeleteDirectory(const char* Path, bool Recursive) { // recurse into that if (!DeleteDirectory(fileName, true)) + { + FindClose(hFind); return false; + } } else { // found a file, so delete it if (!DeleteFileA(fileName)) + { + FindClose(hFind); return false; + } } } while (FindNextFileA(hFind, &findData)); FindClose(hFind);