]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
readelf: tidy dump_relr_relocations
authorAlan Modra <amodra@gmail.com>
Tue, 9 Sep 2025 10:45:44 +0000 (20:15 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 9 Sep 2025 21:21:22 +0000 (06:51 +0930)
A comment in display_relocations said "RELRS has been freed by
dump_relr_relocations".  Except that hadn't happened on all return
paths.  Tidy that by freeing relrs allocated in dump_relr_relocations
in that function, and relrs allocated in display_relocation in that
function.

* readelf.c (dump_relr_relocations): Only free relrs allocated
in this function.
(display_relocations): Free relrs here, on error return paths
too.

binutils/readelf.c

index 8162cbb70033755015b9e173340606c1086e23eb..fd9722c8afc9914e64a49321913d8e09a39d66a8 100644 (file)
@@ -1910,12 +1910,14 @@ dump_relr_relocations (Filedata *          filedata,
       return false;
     }
 
+  uint64_t *alloc_relrs = NULL;
   if (relrs == NULL)
     {
       relrs = get_data (NULL, filedata, relr_offset, 1, relr_size,
                        _("RELR relocation data"));
       if (relrs == NULL)
        return false;
+      alloc_relrs = relrs;
     }
 
   /* Paranoia.  */
@@ -2191,7 +2193,7 @@ dump_relr_relocations (Filedata *          filedata,
     }
 
   free (symtab);
-  free (relrs);
+  free (alloc_relrs);
   return true;
 }
 
@@ -9870,12 +9872,18 @@ display_relocations (Elf_Internal_Shdr *  section,
 
       if (symsec->sh_type != SHT_SYMTAB
          && symsec->sh_type != SHT_DYNSYM)
-       return false;
+       {
+         free (relrs);
+         return false;
+       }
     }
 
   if (symsec != NULL
       && !get_symtab (filedata, symsec, &symtab, &nsyms, &strtab, &strtablen))
-    return false;
+    {
+      free (relrs);
+      return false;
+    }
 
   bool res;
 
@@ -9887,8 +9895,7 @@ display_relocations (Elf_Internal_Shdr *  section,
                                   relrs,
                                   symtab, nsyms, strtab, strtablen,
                                   dump_reloc);
-      /* RELRS has been freed by dump_relr_relocations.  */
-      relrs = NULL;
+      free (relrs);
     }
   else
     res = dump_relocations (filedata, rel_offset, rel_size,