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

Potential memory leak in PointerVector pushBack, if internal vector reallocation fails. #1465

Open
Dimi1010 opened this issue Jun 24, 2024 · 0 comments
Labels

Comments

@Dimi1010
Copy link
Collaborator

In large parts of the code base, PoiterVector::pushBack() is being used as pVector.pushBack(new T(...));. With the current pushBack implementation, if the internal call to m_vector.push_back() requires a reallocation and fails, the pointed element is leaked in those cases.

Opening an issue instead of directly addressing it in a PR, because there are a couple possible ways to address it:

  • Assume ownership is transferred at the pushBack call and clean up the element on error.
  • Provide a flag cleanupOnError to let the call site determine if the vector should handle the cleanup or the call site.
  • Assume the call site will handle cleanup of the pointed element on exception and don't do anything in the vector itself.
@Dimi1010 Dimi1010 added the bug label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant