diff options
author | Luca BRUNO <luca.bruno@coreos.com> | 2022-01-10 09:30:11 +0000 |
---|---|---|
committer | Luca BRUNO <luca.bruno@coreos.com> | 2022-01-10 09:30:11 +0000 |
commit | 0b1a0856925c32fffa93c526b9f415d455d71a1d (patch) | |
tree | ada0dff8399dc28ec1dfd11ce5ef5abacaae89f6 | |
parent | 6cb097fb5e765802008d91f745139f7ecbc6fbe4 (diff) | |
download | ostree-0b1a0856925c32fffa93c526b9f415d455d71a1d.tar.gz |
libotutil: avoid leaking builder memory on error
This swaps the order of a couple of input sanity checks, in order
to fix a minor memory leak due to an early-return on the error
path.
Memory for the result is now allocated only after input has been
sanity-checked.
It fixes a static analysis warning highlighted by Coverity.
-rw-r--r-- | src/libotutil/ot-variant-builder.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libotutil/ot-variant-builder.c b/src/libotutil/ot-variant-builder.c index 92ac8ede..754b9323 100644 --- a/src/libotutil/ot-variant-builder.c +++ b/src/libotutil/ot-variant-builder.c @@ -760,10 +760,10 @@ ot_variant_builder_info_new (OtVariantBuilder *builder, const GVariantType *type { OtVariantBuilderInfo *info; - info = (OtVariantBuilderInfo *) g_slice_new0 (OtVariantBuilderInfo); - g_return_val_if_fail (g_variant_type_is_container (type), NULL); + info = (OtVariantBuilderInfo *) g_slice_new0 (OtVariantBuilderInfo); + info->builder = builder; info->type = g_variant_type_copy (type); info->type_info = g_variant_type_info_get (type); @@ -845,10 +845,10 @@ ot_variant_builder_new (const GVariantType *type, { OtVariantBuilder *builder; - builder = (OtVariantBuilder *) g_slice_new0 (OtVariantBuilder); - g_return_val_if_fail (g_variant_type_is_container (type), NULL); + builder = (OtVariantBuilder *) g_slice_new0 (OtVariantBuilder); + builder->head = ot_variant_builder_info_new (builder, type); builder->ref_count = 1; builder->fd = fd; |