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

Fixed memory leak #1251

Merged
merged 2 commits into from Apr 28, 2020
Merged

Fixed memory leak #1251

merged 2 commits into from Apr 28, 2020

Conversation

hlstriker
Copy link
Contributor

When a pack was cleared or destroyed the String and Raw types could cause memory leaks. This happens when "position" is sitting at the end of the vector and can never get past the "if (pos >= elements.length())" statement. This means there is a memory leak in any plugin that clears/destroys a pack with strings and doesn't set the position to length-1 or less beforehand.

When a pack was cleared or destroyed the String and Raw types could cause memory leaks. This happens when "position" is sitting at the end of the vector and can never get past the "if (pos >= elements.length())" statement. This means there is a memory leak in any plugin that clears/destroys a pack with strings and doesn't set the position to length-1 or less beforehand.
Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

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

Thanks for raising this! I think the actual fix is in another spot, what are your thoughts?

core/logic/CDataPack.cpp Show resolved Hide resolved
@KyleSanderson
Copy link
Member

@hlstriker can I get a r? on that additional delete operator for the array? I think after that we should be good here.

@dvander
Copy link
Member

dvander commented Apr 27, 2020

This fix looks very brittle. Really, the RemoveItem loop should not even be necessary. I would either:

(1) Remove the CDataPack cache, since it almost certainly useless, or
(2) Forbid copy construction on CDataPack::InternalPack, then add a move constructor and destructor.

@hlstriker
Copy link
Contributor Author

@KyleSanderson nice catch, seems good.

@dvander, I agree it's not the end all fix. I'd like to implement your suggestions but it's a bit beyond myself and my available time right now.

@KyleSanderson KyleSanderson merged commit d044b13 into alliedmodders:master Apr 28, 2020
fengjixuchui added a commit to fengjixuchui/sourcemod that referenced this pull request Apr 28, 2020
datapack: free all elements on clear (alliedmodders#1251)
snorux pushed a commit to snorux/GFLZE-SourceMod that referenced this pull request Apr 28, 2020
asherkin pushed a commit that referenced this pull request Apr 30, 2020
When a pack was cleared or destroyed the String and Raw types could cause memory leaks. This happens when "position" is sitting at the end of the vector and can never get past the "if (pos >= elements.length())" statement. This means there is a memory leak in any plugin that clears/destroys a pack with strings and doesn't set the position to length-1 or less beforehand.
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.

None yet

4 participants