Closing handles, freeing memory and preventing unneeded file opens#149
Closing handles, freeing memory and preventing unneeded file opens#149thomaslaurenson merged 1 commit intoTheGrayDot:mainfrom
Conversation
| HANDLE hFile; | ||
| if (!SFileOpenFileEx(hArchive, szFileName, SFILE_OPEN_FROM_MPQ, &hFile)) { | ||
| std::cerr << "[!] Failed: File cannot be opened: " << szFileName << std::endl; | ||
| return 1; | ||
| } | ||
|
|
There was a problem hiding this comment.
The call to SFileExtractFile below already does this under the hood. These lines don't add anything I believe.
There was a problem hiding this comment.
Good change - and this also fixes when successfully extracting a file, and the original hFile was never closed. I only noticed this when playing with Valgrind and doing more analysis. So a great fix!
| LCID * fileLocales = (LCID *)malloc(maxLocales * sizeof(LCID)); | ||
| const auto fileLocales = static_cast<LCID *>(malloc(maxLocales * sizeof(LCID))); |
There was a problem hiding this comment.
This seems like a cleaner way to allocate memory.
There was a problem hiding this comment.
Agreed - this is a good fix
thomaslaurenson
left a comment
There was a problem hiding this comment.
Nice fixes overall - more than happy to merge. Thank you Johan!!!
| HANDLE hFile; | ||
| if (!SFileOpenFileEx(hArchive, szFileName, SFILE_OPEN_FROM_MPQ, &hFile)) { | ||
| std::cerr << "[!] Failed: File cannot be opened: " << szFileName << std::endl; | ||
| return 1; | ||
| } | ||
|
|
There was a problem hiding this comment.
Good change - and this also fixes when successfully extracting a file, and the original hFile was never closed. I only noticed this when playing with Valgrind and doing more analysis. So a great fix!
| LCID * fileLocales = (LCID *)malloc(maxLocales * sizeof(LCID)); | ||
| const auto fileLocales = static_cast<LCID *>(malloc(maxLocales * sizeof(LCID))); |
There was a problem hiding this comment.
Agreed - this is a good fix
No description provided.