Skip to content

Closing handles, freeing memory and preventing unneeded file opens#149

Merged
thomaslaurenson merged 1 commit intoTheGrayDot:mainfrom
sjoblomj:fix-leaks
Mar 22, 2026
Merged

Closing handles, freeing memory and preventing unneeded file opens#149
thomaslaurenson merged 1 commit intoTheGrayDot:mainfrom
sjoblomj:fix-leaks

Conversation

@sjoblomj
Copy link
Contributor

@sjoblomj sjoblomj commented Mar 3, 2026

No description provided.

Comment on lines -98 to -103
HANDLE hFile;
if (!SFileOpenFileEx(hArchive, szFileName, SFILE_OPEN_FROM_MPQ, &hFile)) {
std::cerr << "[!] Failed: File cannot be opened: " << szFileName << std::endl;
return 1;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to SFileExtractFile below already does this under the hood. These lines don't add anything I believe.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment on lines -355 to +350
LCID * fileLocales = (LCID *)malloc(maxLocales * sizeof(LCID));
const auto fileLocales = static_cast<LCID *>(malloc(maxLocales * sizeof(LCID)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a cleaner way to allocate memory.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - this is a good fix

@sjoblomj sjoblomj marked this pull request as draft March 3, 2026 09:57
@sjoblomj sjoblomj marked this pull request as ready for review March 3, 2026 10:33
Copy link
Collaborator

@thomaslaurenson thomaslaurenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fixes overall - more than happy to merge. Thank you Johan!!!

Comment on lines -98 to -103
HANDLE hFile;
if (!SFileOpenFileEx(hArchive, szFileName, SFILE_OPEN_FROM_MPQ, &hFile)) {
std::cerr << "[!] Failed: File cannot be opened: " << szFileName << std::endl;
return 1;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment on lines -355 to +350
LCID * fileLocales = (LCID *)malloc(maxLocales * sizeof(LCID));
const auto fileLocales = static_cast<LCID *>(malloc(maxLocales * sizeof(LCID)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - this is a good fix

@thomaslaurenson thomaslaurenson merged commit daf7a02 into TheGrayDot:main Mar 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants