lib: Fix some minor memory leaks
authorJonathan Lebon <jonathan@jlebon.com>
Wed, 25 Jul 2018 21:49:12 +0000 (17:49 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 26 Jul 2018 21:01:19 +0000 (21:01 +0000)
I initially was going to add a `G_DEFINE_AUTOPTR_CLEANUP_FUNC` for
`FetchStaticDeltaData`, but it honestly didn't seem worth mucking around
ownership everywhere and potentially getting it wrong.

Discovered by Coverity.

Closes: #1692
Approved by: cgwalters

src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo-static-delta-compilation.c

index a8fee07633b25aeccc2176b612029eec2425daba..da46ed32750aa9baff0b190490076ce71b7b566b 100644 (file)
@@ -2486,7 +2486,10 @@ process_one_static_delta (OtPullData                 *pull_data,
                                                OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM,
                                                NULL, &inline_delta_part,
                                                cancellable, error))
-            return FALSE;
+            {
+              fetch_static_delta_data_free (fetch_data);
+              return FALSE;
+            }
 
           _ostree_static_delta_part_execute_async (pull_data->repo,
                                                    fetch_data->objects,
index 9084a72f5e866f5f7e2b3606369069bd23b185e5..f06fad684d86d42da14a24b5f23f24ec493ee319 100644 (file)
@@ -313,14 +313,13 @@ finish_part (OstreeStaticDeltaBuilder *builder, GError **error)
 static OstreeStaticDeltaPartBuilder *
 allocate_part (OstreeStaticDeltaBuilder *builder, GError **error)
 {
-  OstreeStaticDeltaPartBuilder *part = g_new0 (OstreeStaticDeltaPartBuilder, 1);
-
   if (builder->parts->len > 0)
     {
       if (!finish_part (builder, error))
         return NULL;
     }
 
+  OstreeStaticDeltaPartBuilder *part = g_new0 (OstreeStaticDeltaPartBuilder, 1);
   part->objects = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref);
   part->payload = g_string_new (NULL);
   part->operations = g_string_new (NULL);