[binutils-gdb] readelf: tidy dump_relr_relocations
Alan Modra
amodra@sourceware.org
Tue Sep 9 21:21:55 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=aa644b671072db219853c95abb1c5956438f6212
commit aa644b671072db219853c95abb1c5956438f6212
Author: Alan Modra <amodra@gmail.com>
Date: Tue Sep 9 20:15:44 2025 +0930
readelf: tidy dump_relr_relocations
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.
Diff:
---
binutils/readelf.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 8162cbb7003..fd9722c8afc 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -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,
More information about the Binutils-cvs
mailing list