From: Alan Modra Date: Tue, 9 Sep 2025 10:45:44 +0000 (+0930) Subject: readelf: tidy dump_relr_relocations X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa644b671072db219853c95abb1c5956438f6212;p=thirdparty%2Fbinutils-gdb.git 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 --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,