aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2025-04-25 21:08:51 +0100
committerNick Alcock <nick.alcock@oracle.com>2025-04-25 21:23:08 +0100
commit88f2c13d1ce8e9ceac2b95a515c6d7ed96b87adb (patch)
tree73487dce07614a39ce5d063f2bbd300caa85869a
parent02bfc04f73232623a5a16722a79717035da3820c (diff)
downloadbinutils-88f2c13d1ce8e9ceac2b95a515c6d7ed96b87adb.zip
binutils-88f2c13d1ce8e9ceac2b95a515c6d7ed96b87adb.tar.gz
binutils-88f2c13d1ce8e9ceac2b95a515c6d7ed96b87adb.tar.bz2
libctf: archive: fix ctf_dict_open_cached error handling
We were misreporting a failure to ctf_dict_open the dict as an out-of-memory error.
-rw-r--r--libctf/ctf-archive.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index e3c7a5f..06363e7 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -717,7 +717,7 @@ static ctf_dict_t *
ctf_dict_open_cached (ctf_archive_t *arc, const char *name, int *errp)
{
ctf_dict_t *fp;
- char *dupname;
+ char *dupname = NULL;
/* Just return from the cache if possible. */
if (arc->ctfi_dicts
@@ -728,10 +728,10 @@ ctf_dict_open_cached (ctf_archive_t *arc, const char *name, int *errp)
}
/* Not yet cached: open it. */
- fp = ctf_dict_open (arc, name, errp);
- dupname = strdup (name);
+ if ((fp = ctf_dict_open (arc, name, errp)) == NULL)
+ goto err;
- if (!fp || !dupname)
+ if ((dupname = strdup (name)) == NULL)
goto oom;
if (arc->ctfi_dicts == NULL)
@@ -762,10 +762,11 @@ ctf_dict_open_cached (ctf_archive_t *arc, const char *name, int *errp)
return fp;
oom:
- ctf_dict_close (fp);
- free (dupname);
if (errp)
*errp = ENOMEM;
+ err:
+ ctf_dict_close (fp);
+ free (dupname);
return NULL;
}