libostree: Variant-related leak plugs and fixes

This tries to avoid leaking GVariantBuilders and GVariants in some
situations. The leaks were usually happening when some error occurred
or because of unclear variant ownership situation.

The former is mostly about making sure that g_variant_builder_clear is
called on builders that didn't finish their variant building process.

The latter is surely more work - sometimes the result of
g_variant_builder_end() should not be passed directly to a function,
but rather stored in a g_autoptr(GVariant), sunk and then passed to a
function. IMO, with an advent of g_autoptr, GVariants should be always
sunk instead of relying on some receiver function sinking it. This
would make an easy-to-follow policy of always sinking your
variants. Functions could then assume that the passed variant is
already sunk. These leaks are still happenning in commands, but they
are less harmful, since that code will not be used by some daemon as a
library routine.

Closes: #291
Approved by: cgwalters
This commit is contained in:
Krzesimir Nowak authored and Colin Walters (automation) committed 2016-05-12 11:17:09 +00:00
1 parent aa946cc136
commit 862e6ecdcc
5 files changed
+25 -16

No files matched your search

+1 -1
View File
@@ -2384,7 +2384,7 @@ get_modified_xattrs (OstreeRepo *self,
if (label)
{
GVariantBuilder *builder;
g_autoptr(GVariantBuilder) builder = NULL;
/* ret_xattrs may be NULL */
builder = ot_util_variant_builder_from_variant (ret_xattrs,