Created
June 1, 2015 21:47
-
-
Save DDuarte/5d55862af8acd297b354 to your computer and use it in GitHub Desktop.
TC resource leaks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a2565665806bf901d0047755adbf561834ddb129 Mon Sep 17 00:00:00 2001 | |
From: DDuarte <[email protected]> | |
Date: Mon, 1 Jun 2015 03:52:14 +0100 | |
Subject: [PATCH] Tools/Extractors: Fix multiple resource leaks when opening | |
Casc files | |
CID 1254588, 1254548, 1254555, 1254545 | |
--- | |
src/tools/map_extractor/System.cpp | 6 ++++-- | |
src/tools/map_extractor/loadlib.cpp | 1 + | |
src/tools/vmap4_extractor/mpqfile.cpp | 1 + | |
3 files changed, 6 insertions(+), 2 deletions(-) | |
diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp | |
index 9059867..387cd9e 100644 | |
--- a/src/tools/map_extractor/System.cpp | |
+++ b/src/tools/map_extractor/System.cpp | |
@@ -261,6 +261,7 @@ uint32 ReadBuild(int locale) | |
if (!CascOpenFile(CascStorage, filename.c_str(), CASC_LOCALE_ALL, 0, &dbcFile)) | |
{ | |
printf("Locale %s not installed.\n", Locales[locale]); | |
+ CascCloseFile(dbcFile); | |
return 0; | |
} | |
@@ -270,6 +271,7 @@ uint32 ReadBuild(int locale) | |
if (!readBytes) | |
{ | |
printf("Fatal error: Not found %s file!\n", filename.c_str()); | |
+ CascCloseFile(dbcFile); | |
exit(1); | |
} | |
@@ -1171,12 +1173,12 @@ void ExtractDBFilesClient(int l) | |
if (!FileExists(filename.c_str())) | |
if (ExtractFile(dbcFile, filename.c_str())) | |
++count; | |
- | |
- CascCloseFile(dbcFile); | |
} | |
else | |
printf("Unable to open file %s in the archive for locale %s: %s\n", fileName, Locales[l], HumanReadableCASCError(GetLastError())); | |
+ CascCloseFile(dbcFile); | |
+ | |
fileName = DBFilesClientList[++index]; | |
} | |
diff --git a/src/tools/map_extractor/loadlib.cpp b/src/tools/map_extractor/loadlib.cpp | |
index 4a9b353..e33c4f8 100644 | |
--- a/src/tools/map_extractor/loadlib.cpp | |
+++ b/src/tools/map_extractor/loadlib.cpp | |
@@ -42,6 +42,7 @@ bool ChunkedFile::loadFile(HANDLE mpq, char* filename, bool log) | |
{ | |
if (log) | |
printf("No such file %s\n", filename); | |
+ CascCloseFile(file); | |
return false; | |
} | |
diff --git a/src/tools/vmap4_extractor/mpqfile.cpp b/src/tools/vmap4_extractor/mpqfile.cpp | |
index 87b0b5b..86c160f 100644 | |
--- a/src/tools/vmap4_extractor/mpqfile.cpp | |
+++ b/src/tools/vmap4_extractor/mpqfile.cpp | |
@@ -14,6 +14,7 @@ MPQFile::MPQFile(HANDLE mpq, const char* filename, bool warnNoExist /*= true*/) | |
if (warnNoExist || GetLastError() != ERROR_FILE_NOT_FOUND) | |
fprintf(stderr, "Can't open %s, err=%u!\n", filename, GetLastError()); | |
eof = true; | |
+ CascCloseFile(file); | |
return; | |
} | |
-- | |
1.9.5.msysgit.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment