From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA] Use std::string in reread_symbols
Date: Sat, 19 May 2018 15:23:00 -0000 [thread overview]
Message-ID: <20180519151713.17535-1-tom@tromey.com> (raw)
This removes a cleanup from reread_symbols by using std::string. This
fixes a memory leak, because this cleanup is ordinarily discarded, not
run.
Tested by the buildbot.
gdb/ChangeLog
2018-05-19 Tom Tromey <tom@tromey.com>
* symfile.c (reread_symbols): Use std::string for original_name.
---
gdb/ChangeLog | 4 ++++
gdb/symfile.c | 9 ++++-----
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 1f5d761877..7bc03fbb8f 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2316,7 +2316,6 @@ reread_symbols (void)
struct cleanup *old_cleanups;
struct section_offsets *offsets;
int num_offsets;
- char *original_name;
printf_unfiltered (_("`%s' has changed; re-reading symbols.\n"),
objfile_name (objfile));
@@ -2382,8 +2381,7 @@ reread_symbols (void)
error (_("Can't open %s to read symbols."), obfd_filename);
}
- original_name = xstrdup (objfile->original_name);
- make_cleanup (xfree, original_name);
+ std::string original_name = objfile->original_name;
/* bfd_openr sets cacheable to true, which is what we want. */
if (!bfd_check_format (objfile->obfd, bfd_object))
@@ -2429,8 +2427,9 @@ reread_symbols (void)
set_objfile_per_bfd (objfile);
objfile->original_name
- = (char *) obstack_copy0 (&objfile->objfile_obstack, original_name,
- strlen (original_name));
+ = (char *) obstack_copy0 (&objfile->objfile_obstack,
+ original_name.c_str (),
+ original_name.size ());
/* Reset the sym_fns pointer. The ELF reader can change it
based on whether .gdb_index is present, and we need it to
--
2.13.6
next reply other threads:[~2018-05-19 15:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-19 15:23 Tom Tromey [this message]
2018-05-20 23:49 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180519151713.17535-1-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox