summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadislav <Zezula>2013-12-16 17:02:44 +0100
committerLadislav <Zezula>2013-12-16 17:02:44 +0100
commit55f159cf69d8b4816876653d25239abf6c3ef5a4 (patch)
tree7f9dd1d21d8dd5e207a6ef9765de15a02842cc78
parent60ef0346ba14b7153c9efd40d0aa6dd01d1d2671 (diff)
+ Fixed handle problem
-rw-r--r--src/SFileListFile.cpp26
-rw-r--r--test/Test.cpp4
2 files changed, 18 insertions, 12 deletions
diff --git a/src/SFileListFile.cpp b/src/SFileListFile.cpp
index 058fc7a..b2db0c5 100644
--- a/src/SFileListFile.cpp
+++ b/src/SFileListFile.cpp
@@ -50,13 +50,8 @@ static char * CopyListLine(char * szListLine, const char * szFileName)
static bool FreeListFileCache(TListFileCache * pCache)
{
// Valid parameter check
- if(pCache == NULL)
- return false;
-
- // Close the listfile
- if(pCache->hFile != NULL)
- SFileCloseFile(pCache->hFile);
- STORM_FREE(pCache);
+ if(pCache != NULL)
+ STORM_FREE(pCache);
return true;
}
@@ -575,6 +570,10 @@ HANDLE WINAPI SListFileFindFirstFile(HANDLE hMpq, const char * szListFile, const
// Perform file search
if(nError == ERROR_SUCCESS)
{
+ // The listfile handle is in the cache now
+ hListFile = NULL;
+
+ // Iterate through the listfile
for(;;)
{
// Read the (next) line
@@ -601,6 +600,10 @@ HANDLE WINAPI SListFileFindFirstFile(HANDLE hMpq, const char * szListFile, const
memset(lpFindFileData, 0, sizeof(SFILE_FIND_DATA));
SetLastError(nError);
}
+
+ // Close remaining unowned listfile handle
+ if(hListFile != NULL)
+ SFileCloseFile(hListFile);
return (HANDLE)pCache;
}
@@ -639,6 +642,13 @@ bool WINAPI SListFileFindNextFile(HANDLE hFind, SFILE_FIND_DATA * lpFindFileData
bool WINAPI SListFileFindClose(HANDLE hFind)
{
- return FreeListFileCache((TListFileCache *)hFind);
+ TListFileCache * pCache = (TListFileCache *)hFind;
+
+ if(pCache == NULL)
+ return false;
+
+ if(pCache->hFile != NULL)
+ SFileCloseFile(pCache->hFile);
+ return FreeListFileCache(pCache);
}
diff --git a/test/Test.cpp b/test/Test.cpp
index 7487cad..a9cc5e6 100644
--- a/test/Test.cpp
+++ b/test/Test.cpp
@@ -2911,10 +2911,6 @@ int main(int argc, char * argv[])
// Open an empty archive (found in WoW cache - it's just a header)
if(nError == ERROR_SUCCESS)
- nError = TestOpenArchive("WoW-1.2.4-to-1.3.0-enGB-patch.exe");
-
- // Open an empty archive (found in WoW cache - it's just a header)
- if(nError == ERROR_SUCCESS)
nError = TestOpenArchive("MPQ_2012_v2_EmptyMpq.MPQ");
// Open an empty archive (created artificially - it's just a header)