libctf, archive, link: fix parent importing

We are about to move to a regime where there are very few things you can do
with most dicts before you ctf_import them.  So emit a warning if
ctf_archive_next()'s convenience ctf_import of parents fails.  Rip out the
buggy code in ctf_link_deduplicating_open_inputs which opened the parent by
hand (with a hardwired name), and instead rely on ctf_archive_next to do it
for us (which also means we don't end up opening it twice, once in
ctf_archive_next, once in ctf_link_deduplicating_open_inputs).

While we're there, arrange to close the inputs we already opened if opening
of some inputs fails, rather than leaking them.  (There are still some leaks
here, so add a comment to remind us to clean them up later.)

libctf/
	* ctf-archive.c (ctf_arc_import_parent): Emit a warning if importing
	fails.
	* ctf-link.c (ctf_link_deduplicating_open_inputs): Rely on the
        ctf_archive_next to open parent dicts.
This commit is contained in:
Nick Alcock
2024-07-15 20:33:24 +01:00
parent 9a74ab12c8
commit 30cced0da6
2 changed files with 78 additions and 41 deletions

View File

@@ -769,7 +769,10 @@ ctf_arc_import_parent (const ctf_archive_t *arc, ctf_dict_t *fp, int *errp)
if (parent)
{
ctf_import (fp, parent);
if (ctf_import (fp, parent) < 0)
ctf_err_warn (NULL, 1, ctf_errno (fp),
"ctf_arc_import_parent: cannot import: %s",
ctf_errmsg (ctf_errno (fp)));
ctf_dict_close (parent);
}
else if (err != ECTF_ARNNAME)