]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: archive: fix ctf_dict_open_cached error handling
authorNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 20:08:51 +0000 (21:08 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 20:23:08 +0000 (21:23 +0100)
We were misreporting a failure to ctf_dict_open the dict as
an out-of-memory error.

libctf/ctf-archive.c

index e3c7a5f55a9d5235ff174324c52053e9e063cbc6..06363e7e200facebb5e8c02ee1058b984590cef5 100644 (file)
@@ -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;
 }