bfd_get_unique_section_name leak

Alan Modra amodra@gmail.com
Wed Jan 15 12:05:42 GMT 2025


The name returned by this function is used in asection->name, so
needs to persist until a bfd is closed.

	* section.c (bfd_get_unique_section_name): Return an alloc'd
	string.

diff --git a/bfd/section.c b/bfd/section.c
index e7674c9dc1a..ffd28911297 100644
--- a/bfd/section.c
+++ b/bfd/section.c
@@ -1063,7 +1063,7 @@ bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count)
   char *sname;
 
   len = strlen (templat);
-  sname = (char *) bfd_malloc (len + 8);
+  sname = bfd_alloc (abfd, len + 8);
   if (sname == NULL)
     return NULL;
   memcpy (sname, templat, len);

-- 
Alan Modra


More information about the Binutils mailing list