ostree/dump: Fix a memory leak
authorPhilip Withnall <withnall@endlessm.com>
Mon, 10 Aug 2020 11:07:22 +0000 (12:07 +0100)
committerPhilip Withnall <pwithnall@endlessos.org>
Thu, 1 Oct 2020 10:06:56 +0000 (11:06 +0100)
Re-using the `refs` variable for the main list of refs, plus the
iterated lists, meant that the main list was never freed (although all
the iterated ones were freed correctly).

Fix this by using two variables rather than reusing the one.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
src/ostree/ot-dump.c

index 1f911d4ef9d61b8c4fa3ed55635b12be8adb6fe7..a8ed54a2ee1de08ec52d1ff520dffd154b7090fd 100644 (file)
@@ -322,10 +322,11 @@ ot_dump_summary_bytes (GBytes          *summary_bytes,
   collection_map = g_variant_lookup_value (exts, OSTREE_SUMMARY_COLLECTION_MAP, G_VARIANT_TYPE ("a{sa(s(taya{sv}))}"));
   if (collection_map != NULL)
     {
+      g_autoptr(GVariant) collection_refs = NULL;
       g_variant_iter_init (&iter, collection_map);
 
-      while (g_variant_iter_loop (&iter, "{&s@a(s(taya{sv}))}", &collection_id, &refs))
-        dump_summary_refs (collection_id, refs);
+      while (g_variant_iter_loop (&iter, "{&s@a(s(taya{sv}))}", &collection_id, &collection_refs))
+        dump_summary_refs (collection_id, collection_refs);
     }
 
   /* Print out the additional metadata. */