readelf: tidy dump_relr_relocations
Commit Message
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.
@@ -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,