ref: 5761edbc87f683fb807512cd5d1e4424654d23d8
parent: 2ce02fea7b350de9ddfbcf542ba4dd59a8ab255b
author: Wolfgang Stöggl <c72578@yahoo.de>
date: Sun Jul 7 02:30:38 EDT 2019
win32-glob: fix resource leak on bad pattern Open the HANDLE hfindfile later, after the checks of pattern, flags, unused, pglob and length of file name. This avoids a possible return from function glob() without FindClose(hfindfile). - Fixes the following Cppcheck errors: [src/win32-glob.c:80] (error) Resource leak: hfindfile [resourceLeak] [src/win32-glob.c:88] (error) Resource leak: hfindfile [resourceLeak]
--- a/src/win32-glob.c
+++ b/src/win32-glob.c
@@ -72,7 +72,7 @@
size_t len;
unsigned entries = 0;
WIN32_FIND_DATAA finddata;
- HANDLE hfindfile = FindFirstFileA(pattern, &finddata);
+ HANDLE hfindfile;
if (!pattern || flags != (flags & GLOB_FLAGS) || unused || !pglob)
{
@@ -93,6 +93,7 @@
len--;
path[len] = 0;
+ hfindfile = FindFirstFileA(pattern, &finddata);
if (hfindfile == INVALID_HANDLE_VALUE)
{
if (flags & GLOB_NOCHECK)