aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-09-02 09:54:55 +0930
committerAlan Modra <amodra@gmail.com>2019-09-02 10:08:17 +0930
commit22b31fea07587034636251ccb81041e4e8e0bd93 (patch)
tree5485ca7806b23b07d21790842f821eadae1f8067
parentAutomatic date update in version.in (diff)
downloadbinutils-gdb-22b31fea07587034636251ccb81041e4e8e0bd93.tar.gz
binutils-gdb-22b31fea07587034636251ccb81041e4e8e0bd93.tar.bz2
binutils-gdb-22b31fea07587034636251ccb81041e4e8e0bd93.zip
Memory leak in dwarf2.c
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.
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/dwarf2.c16
2 files changed, 15 insertions, 7 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 2b063837683..47f694ad75f 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2019-09-02 Alan Modra <amodra@gmail.com>
+
+ PR 11983
+ * dwarf2.c (_bfd_dwarf2_slurp_debug_info): Free debug_filename
+ on success. Tidy.
+
2019-08-31 Jim Wilson <jimw@sifive.com>
PR 23825
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index a8beec49472..88638b903f7 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;
}