From patchwork Thu Nov 2 22:36:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 24060 Received: (qmail 17818 invoked by alias); 2 Nov 2017 22:38:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17779 invoked by uid 89); 2 Nov 2017 22:38:17 -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=rfa X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.125) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Nov 2017 22:38:15 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 16E50552D9D for ; Thu, 2 Nov 2017 17:36:16 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id AO5weibHL5b6TAO5wexSsC; Thu, 02 Nov 2017 17:36:16 -0500 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:58978 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eAO5v-003CfJ-Sk; Thu, 02 Nov 2017 17:36:16 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 04/13] Use unique_xmalloc_ptr in find_separate_debug_file_by_debuglink Date: Thu, 2 Nov 2017 16:36:03 -0600 Message-Id: <20171102223612.3642-5-tom@tromey.com> In-Reply-To: <20171102223612.3642-1-tom@tromey.com> References: <20171102223612.3642-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eAO5v-003CfJ-Sk X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya.Home) [71.218.90.63]:58978 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes find_separate_debug_file_by_debuglink to use unique_xmalloc_ptr, removing some cleanups. gdb/ChangeLog 2017-11-02 Tom Tromey * symfile.c (find_separate_debug_file_by_debuglink): Use unique_xmalloc_ptr. --- gdb/ChangeLog | 5 +++++ gdb/symfile.c | 36 ++++++++++++++---------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index 69358e44ce..fb63441ac0 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1545,13 +1545,11 @@ terminate_after_last_dir_separator (char *path) char * find_separate_debug_file_by_debuglink (struct objfile *objfile) { - char *debuglink; - char *dir, *canon_dir; char *debugfile; unsigned long crc32; - struct cleanup *cleanups; - debuglink = bfd_get_debug_link_info (objfile->obfd, &crc32); + gdb::unique_xmalloc_ptr debuglink + (bfd_get_debug_link_info (objfile->obfd, &crc32)); if (debuglink == NULL) { @@ -1560,15 +1558,12 @@ find_separate_debug_file_by_debuglink (struct objfile *objfile) return NULL; } - cleanups = make_cleanup (xfree, debuglink); - dir = xstrdup (objfile_name (objfile)); - make_cleanup (xfree, dir); - terminate_after_last_dir_separator (dir); - canon_dir = lrealpath (dir); + std::string dir = objfile_name (objfile); + terminate_after_last_dir_separator (&dir[0]); + gdb::unique_xmalloc_ptr canon_dir (lrealpath (dir.c_str ())); - debugfile = find_separate_debug_file (dir, canon_dir, debuglink, - crc32, objfile); - xfree (canon_dir); + debugfile = find_separate_debug_file (dir.c_str (), canon_dir.get (), + debuglink.get (), crc32, objfile); if (debugfile == NULL) { @@ -1580,19 +1575,17 @@ find_separate_debug_file_by_debuglink (struct objfile *objfile) if (lstat (objfile_name (objfile), &st_buf) == 0 && S_ISLNK (st_buf.st_mode)) { - char *symlink_dir; - - symlink_dir = lrealpath (objfile_name (objfile)); + gdb::unique_xmalloc_ptr symlink_dir + (lrealpath (objfile_name (objfile))); if (symlink_dir != NULL) { - make_cleanup (xfree, symlink_dir); - terminate_after_last_dir_separator (symlink_dir); - if (strcmp (dir, symlink_dir) != 0) + terminate_after_last_dir_separator (symlink_dir.get ()); + if (strcmp (dir.c_str (), symlink_dir.get ()) != 0) { /* Different directory, so try using it. */ - debugfile = find_separate_debug_file (symlink_dir, - symlink_dir, - debuglink, + debugfile = find_separate_debug_file (symlink_dir.get (), + symlink_dir.get (), + debuglink.get (), crc32, objfile); } @@ -1600,7 +1593,6 @@ find_separate_debug_file_by_debuglink (struct objfile *objfile) } } - do_cleanups (cleanups); return debugfile; }