aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2024-04-26 18:10:00 +0100
committerNick Alcock <nick.alcock@oracle.com>2024-05-17 12:58:17 +0100
commit2dd3fd0de417e62bb3cd9b01c4b4f35e372905cf (patch)
tree64a47524bf0b4f4580725b1e3fbdb61e81543035
parent61914bb6990c943c65fa8e10b1577c0808016149 (diff)
downloadfsf-binutils-gdb-2dd3fd0de417e62bb3cd9b01c4b4f35e372905cf.zip
fsf-binutils-gdb-2dd3fd0de417e62bb3cd9b01c4b4f35e372905cf.tar.gz
fsf-binutils-gdb-2dd3fd0de417e62bb3cd9b01c4b4f35e372905cf.tar.bz2
libctf: ctf_archive_iter: fix tiny leak
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.
-rw-r--r--libctf/ctf-archive.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index 451d6c6..f459c02 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -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;
}