aboutsummaryrefslogtreecommitdiff
path: root/bfd/dwarf2.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-09-02 16:48:44 +0930
committerAlan Modra <amodra@gmail.com>2019-09-02 16:50:22 +0930
commit217d2eaa69c2a5d58cdfd11619c4f2e41c986826 (patch)
tree924335b83afc5927cebccafe369e9d80df9d7942 /bfd/dwarf2.c
parent22b31fea07587034636251ccb81041e4e8e0bd93 (diff)
downloadgdb-217d2eaa69c2a5d58cdfd11619c4f2e41c986826.zip
gdb-217d2eaa69c2a5d58cdfd11619c4f2e41c986826.tar.gz
gdb-217d2eaa69c2a5d58cdfd11619c4f2e41c986826.tar.bz2
Re: Memory leak in dwarf2.c
PR 11983 * dwarf2.c (read_alt_indirect_string): Free debug_filename on success. Tidy. (read_alt_indirect_ref): Likewise.
Diffstat (limited to 'bfd/dwarf2.c')
-rw-r--r--bfd/dwarf2.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index 88638b9..ed6dcd4 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -802,20 +802,21 @@ read_alt_indirect_string (struct comp_unit * unit,
if (stash->alt_bfd_ptr == NULL)
{
- bfd * debug_bfd;
- char * debug_filename = bfd_follow_gnu_debugaltlink (unit->abfd, DEBUGDIR);
+ bfd *debug_bfd;
+ char *debug_filename = bfd_follow_gnu_debugaltlink (unit->abfd, DEBUGDIR);
if (debug_filename == NULL)
return NULL;
- if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
- || ! bfd_check_format (debug_bfd, bfd_object))
- {
- if (debug_bfd)
- bfd_close (debug_bfd);
+ 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 NULL;
- /* FIXME: Should we report our failure to follow the debuglink ? */
- free (debug_filename);
+ if (!bfd_check_format (debug_bfd, bfd_object))
+ {
+ bfd_close (debug_bfd);
return NULL;
}
stash->alt_bfd_ptr = debug_bfd;
@@ -850,20 +851,21 @@ read_alt_indirect_ref (struct comp_unit * unit,
if (stash->alt_bfd_ptr == NULL)
{
- bfd * debug_bfd;
- char * debug_filename = bfd_follow_gnu_debugaltlink (unit->abfd, DEBUGDIR);
+ bfd *debug_bfd;
+ char *debug_filename = bfd_follow_gnu_debugaltlink (unit->abfd, DEBUGDIR);
if (debug_filename == NULL)
return FALSE;
- if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
- || ! bfd_check_format (debug_bfd, bfd_object))
- {
- if (debug_bfd)
- bfd_close (debug_bfd);
+ 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 NULL;
- /* FIXME: Should we report our failure to follow the debuglink ? */
- free (debug_filename);
+ if (!bfd_check_format (debug_bfd, bfd_object))
+ {
+ bfd_close (debug_bfd);
return NULL;
}
stash->alt_bfd_ptr = debug_bfd;