From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92632 invoked by alias); 19 May 2018 15:17:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 92621 invoked by uid 89); 19 May 2018 15:17:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1597 X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.44.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 19 May 2018 15:17:16 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 6082D4012AFA1 for ; Sat, 19 May 2018 10:17:15 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id K3bffVfIFWCOCK3bffLyCg; Sat, 19 May 2018 10:17:15 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:36430 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fK3bf-002Mw2-4I; Sat, 19 May 2018 10:17:15 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Use std::string in reread_symbols Date: Sat, 19 May 2018 15:23:00 -0000 Message-Id: <20180519151713.17535-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fK3bf-002Mw2-4I X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:36430 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-05/txt/msg00436.txt.bz2 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 * 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