Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
GError
s 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 inutil
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.