-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory leaks in Assembler::CreateExportDirectory #50431
Conversation
Use smart pointers to avoid having to manually deallocate memory. - szOutputFileName was never being deallocated - `pAlias` and `exportDirData` were only being deallocated on the success path and not on any of the error paths.
memset(exportDirData,0,exportDirDataSize); | ||
|
||
// Export address table | ||
DWORD* pEAT = (DWORD*)exportDirData; | ||
DWORD* pEAT = (DWORD*)(BYTE*)exportDirData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a change in this PR, but a DWORD
(unsigned int
on my machine) might have a different alignment than a BYTE
(char
on my machine). Could this fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
malloc on Linux returns 8 byte aligned memory for 32 bit systems and 16 byte aligned ones on 64 bit systems. See https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html. I assume new would behave the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Hello @janvorli! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Use smart pointers to avoid having to manually deallocate memory.
szOutputFileName was never being deallocated
pAlias
andexportDirData
were only being deallocated on the success path and not on any of the error paths.