]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gnu_debuglink related memory leak
authorAlan Modra <amodra@gmail.com>
Wed, 1 Jan 2025 12:22:41 +0000 (22:52 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 1 Jan 2025 12:22:41 +0000 (22:52 +1030)
* opncls.c (bfd_fill_in_gnu_debuglink_section): Free section
contents on success too.

bfd/opncls.c

index fb0bca7689abf02d2891bad7a0f0cbaa3026f9ba..a0b30f568d7102f85e553f8578bf49efcd125252 100644 (file)
@@ -1768,7 +1768,7 @@ bfd_fill_in_gnu_debuglink_section (bfd *abfd,
   debuglink_size &= ~3;
   debuglink_size += 4;
 
-  contents = (char *) bfd_malloc (debuglink_size);
+  contents = bfd_malloc (debuglink_size);
   if (contents == NULL)
     {
       /* XXX Should we delete the section from the bfd ?  */
@@ -1781,14 +1781,9 @@ bfd_fill_in_gnu_debuglink_section (bfd *abfd,
 
   bfd_put_32 (abfd, crc32, contents + crc_offset);
 
-  if (! bfd_set_section_contents (abfd, sect, contents, 0, debuglink_size))
-    {
-      /* XXX Should we delete the section from the bfd ?  */
-      free (contents);
-      return false;
-    }
-
-  return true;
+  bool ret = bfd_set_section_contents (abfd, sect, contents, 0, debuglink_size);
+  free (contents);
+  return ret;
 }
 
 /* Finds the build-id associated with @var{abfd}.  If the build-id is