[PATCH] winedbg: close filehandle on one exit branch (Coverity)

Marcus Meissner marcus at jet.franken.de
Thu May 7 03:39:20 CDT 2015


CID 713852 Resource leak

This is a non-error path which might be called multiple times, so
avoid leaking here.
---
 programs/winedbg/source.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/programs/winedbg/source.c b/programs/winedbg/source.c
index e564815..35871dd 100644
--- a/programs/winedbg/source.c
+++ b/programs/winedbg/source.c
@@ -87,7 +87,10 @@ static  void*   source_map_file(const char* name, HANDLE* hMap, unsigned* size)
     hFile = CreateFileA(name, GENERIC_READ, FILE_SHARE_READ, NULL,
                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
     if (hFile == INVALID_HANDLE_VALUE) return (void*)-1;
-    if (size != NULL && (*size = GetFileSize(hFile, NULL)) == -1) return (void*)-1;
+    if (size != NULL && (*size = GetFileSize(hFile, NULL)) == -1) {
+        CloseHandle(hFile);
+        return (void*)-1;
+    }
     *hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
     CloseHandle(hFile);
     if (!*hMap) return (void*)-1;
-- 
1.8.4.5




More information about the wine-patches mailing list