Skip to content
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

Merged
1 commit merged into from
Apr 16, 2021

Conversation

omajid
Copy link
Member

@omajid omajid commented Mar 30, 2021

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.

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;
Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@janvorli janvorli closed this Apr 8, 2021
@janvorli janvorli reopened this Apr 8, 2021
@ghost
Copy link

ghost commented Apr 8, 2021

Hello @janvorli!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

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 (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit ff17846 into dotnet:main Apr 16, 2021
@ghost ghost locked as resolved and limited conversation to collaborators May 16, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants