]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: ctf_archive_iter: fix tiny leak
authorNick Alcock <nick.alcock@oracle.com>
Fri, 26 Apr 2024 17:10:00 +0000 (18:10 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 17 May 2024 11:58:17 +0000 (12:58 +0100)
If iteration fails because opening a dict has failed, ctf_archive_next does
not destroy the iterator, so the caller can keep going and try to open other
dicts further into the archive.  ctf_archive_iter just returns, though, so
it should free the iterator rather than leaking it.

libctf/
* ctf-archive.c (ctf_archive_iter): Don't leak the iterator on
failure.

libctf/ctf-archive.c

index 451d6c697355e1e538f3d17a51c64bdcd78ffd86..f459c02e702fc4195eb8e3ace1aeb6aa5799c014 100644 (file)
@@ -1063,7 +1063,7 @@ ctf_archive_iter (const ctf_archive_t *arc, ctf_archive_member_f *func,
   ctf_next_t *i = NULL;
   ctf_dict_t *fp;
   const char *name;
-  int err;
+  int err = 0;
 
   while ((fp = ctf_archive_next (arc, &i, &name, 0, &err)) != NULL)
     {
@@ -1077,6 +1077,11 @@ ctf_archive_iter (const ctf_archive_t *arc, ctf_archive_member_f *func,
        }
       ctf_dict_close (fp);
     }
+  if (err != ECTF_NEXT_END && err != 0)
+    {
+      ctf_next_destroy (i);
+      return -1;
+    }
   return 0;
 }