[PATCH] bfd: fix memory allocation (PR 26005)
Gunther Nikl
gnikl@justmail.de
Tue May 19 16:20:03 GMT 2020
Hello Nick!
To fix PR 26005 you replaced a bfd_zalloc with bfd_malloc + memset. However,
the memset call is misplaced since it is before the NULL check. The following
patch uses bfd_zmalloc avoiding the need for memset.
Regards,
Gunther
--- cut ---
2020-05-18 Gunther Nikl <gnikl@justmail.de>
PR 26005
* elf.c (bfd_section_from_shdr): Replace bfd_malloc + memset with
bfd_zmalloc to allocate memory for the sections_being_created array.
diff --git a/bfd/elf.c b/bfd/elf.c
index c74d95b442..0664f9ffeb 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -2074,8 +2074,7 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
/* PR 26005: Do not use bfd_zalloc here as the memory might
be released before the bfd has been fully scanned. */
- sections_being_created = (bfd_boolean *) bfd_malloc (amt);
- memset (sections_being_created, FALSE, amt);
+ sections_being_created = (bfd_boolean *) bfd_zmalloc (amt);
if (sections_being_created == NULL)
return FALSE;
sections_being_created_abfd = abfd;
--- cut ---
More information about the Binutils
mailing list