From 7a87e9c80506af4c3f658c1a796c4ad18730e46c Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 18 May 2020 20:44:30 +0930 Subject: [PATCH] ECOFF slurp_relocs thinko In git commit 806470a219 I swapped the order of internal vs. external relocs memory allocation in ecoff_slurp_reloc_table, the idea being that the external reloc size can be sanity checked against file size. However, that fails badly with bfd_alloc memory where releasing any block also releases all more recently allocated blocks. * ecoff.c (ecoff_slurp_reloc_table): Malloc external_relocs so they can be freed without also freeing internal_relocs. --- bfd/ChangeLog | 5 +++++ bfd/ecoff.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index b3cefd9488..0e5dec08d6 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2020-05-18 Alan Modra + + * ecoff.c (ecoff_slurp_reloc_table): Malloc external_relocs so + they can be freed without also freeing internal_relocs. + 2020-05-18 Jaydeep Chauhan PR 25713 diff --git a/bfd/ecoff.c b/bfd/ecoff.c index 50a133b7ba..82267a889d 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c @@ -1626,7 +1626,7 @@ ecoff_slurp_reloc_table (bfd *abfd, amt = external_reloc_size * section->reloc_count; if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0) return FALSE; - external_relocs = _bfd_alloc_and_read (abfd, amt, amt); + external_relocs = _bfd_malloc_and_read (abfd, amt, amt); if (external_relocs == NULL) return FALSE; @@ -1635,7 +1635,7 @@ ecoff_slurp_reloc_table (bfd *abfd, internal_relocs = (arelent *) bfd_alloc (abfd, amt); if (internal_relocs == NULL) { - bfd_release (abfd, external_relocs); + free (external_relocs); return FALSE; } @@ -1703,7 +1703,7 @@ ecoff_slurp_reloc_table (bfd *abfd, (*backend->adjust_reloc_in) (abfd, &intern, rptr); } - bfd_release (abfd, external_relocs); + free (external_relocs); section->relocation = internal_relocs; -- 2.34.1