Fix memory leaks detected by running testlibrary with AddressSanitizer #5690
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.
This PR just fixes leaks detected in the production code. A follow-up PR will get testlibrary passing.
main: Use g_autoptr for the GOptionContext
No functional change, but it will make it easier to avoid leaking it.
main: Return from flatpak_run() instead of calling exit()
This allows g_autoptr destructors to run, avoiding memory leaks being
reported by AddressSanitizer; they would be harmless, since we're about
to exit anyway, but AddressSanitizer can't tell the difference between
an O(n) problem and an O(1) harmless "leak".
dir: Don't store a pointer in a gsize
This is, strictly speaking, not allowed. On uncommon architectures like
CHERI, a pointer can be larger than a gsize.
This might also help to avoid AddressSanitizer losing track of
reachability, so that it won't think the array and its contents have
been leaked.
populate_commit_data_cache: Don't leak child value
g_variant_get_child_value() returns a non-floating reference, so
g_variant_builder_add() will not sink it.
populate_commit_data_cache: Don't leak a floating GVariant
var_variant_dup_to_gvariant() returns a floating GVariant, and
g_variant_get_child_value() won't sink it, so we need to free it.
session-helper: Don't leak the GOptionContext
flatpak_remote_commit_filter: Don't leak config GKeyFile
flatpak-bwrap: Don't leak runtime_dir_members
system-helper: Don't leak the GCancellable for each OngoingPull