bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory leak in dwarf2.c


From: Alan Modra
Subject: Re: Memory leak in dwarf2.c
Date: Mon, 2 Sep 2019 11:03:20 +0930
User-agent: Mutt/1.9.4 (2018-02-28)

On Sun, Sep 01, 2019 at 10:27:03PM +0200, Torsten Rupp wrote:
> In function_bfd_dwarf2_slurp_debug_info(), line 4367 the following call
> is made for the scoped variable debug_filename:
> 
>       debug_filename = bfd_follow_build_id_debuglink (abfd, DEBUGDIR);
> 
> The returned value is allocated, but this memory is not freed in that
> scope in all cases.

This fixes a small leak of debug_filename.  bfd_openr copies the file
name since git commit 1be5090bca.

        PR 11983
        * dwarf2.c (_bfd_dwarf2_slurp_debug_info): Free debug_filename
        on success.  Tidy.

diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index a8beec4947..88638b903f 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -4385,18 +4385,20 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd,
           fail more quickly.  */
        return FALSE;
 
+      debug_bfd = bfd_openr (debug_filename, NULL);
+      free (debug_filename);
+      if (debug_bfd == NULL)
+       /* FIXME: Should we report our failure to follow the debuglink ?  */
+       return FALSE;
+
       /* Set BFD_DECOMPRESS to decompress debug sections.  */
-      if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
-         || !(debug_bfd->flags |= BFD_DECOMPRESS,
-              bfd_check_format (debug_bfd, bfd_object))
+      debug_bfd->flags |= BFD_DECOMPRESS;
+      if (!bfd_check_format (debug_bfd, bfd_object)
          || (msec = find_debug_info (debug_bfd,
                                      debug_sections, NULL)) == NULL
          || !bfd_generic_link_read_symbols (debug_bfd))
        {
-         if (debug_bfd)
-           bfd_close (debug_bfd);
-         /* FIXME: Should we report our failure to follow the debuglink ?  */
-         free (debug_filename);
+         bfd_close (debug_bfd);
          return FALSE;
        }
 


-- 
Alan Modra
Australia Development Lab, IBM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]