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 potential memory leaks #2586

Merged
merged 5 commits into from
Oct 21, 2023

Conversation

taminob
Copy link
Contributor

@taminob taminob commented Oct 20, 2023

While looking through the source code, I found a few potential memory leaks.

Most of them were caused by early returns (e.g. because of an exception) without freeing a resource first.
To prevent those and make the code more robust, I added a scope_guard which will ensure via RAII that the resources are freed.
Additionally, I added them in a few places where GErrors are in use and where I think there might be a risk in the future.

Instead of this custom scope_guard it could also be considered to use a third-party library but I think it's easier to provide this simple functionality in util instead of integrating yet another dependency.

I tried to group the different kinds of fixes I did in different commits, I'll squash them in the end to make history more readable.
Also, I made the fixes as small as possible to avoid regressions or break something by accident.

@taminob taminob force-pushed the bugfix/fix-potential-memory-leaks branch from 2c63d6b to ae748b2 Compare October 21, 2023 09:52
@taminob
Copy link
Contributor Author

taminob commented Oct 21, 2023

Sorry that I forgot to auto-format the commits. Should be fixed now.

I noticed that the CI doesn't seem to check the hpp files which also had a formatting inconsistency in the previous commits (see #2589).

@Alexays
Copy link
Owner

Alexays commented Oct 21, 2023

LGTM thanks!

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