From patchwork Wed Feb 7 22:04:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 25871 Received: (qmail 4327 invoked by alias); 7 Feb 2018 22:04:46 -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 3914 invoked by uid 89); 7 Feb 2018 22:04:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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=H*RU:192.185.50.66, Hx-spam-relays-external:192.185.50.66 X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.50.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Feb 2018 22:04:42 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 1FE7C19B25 for ; Wed, 7 Feb 2018 16:04:41 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id jXpZel3pf0aRHjXpZe5JAI; Wed, 07 Feb 2018 16:04:41 -0600 Received: from 174-29-33-254.hlrn.qwest.net ([174.29.33.254]:59168 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ejXpY-002nlZ-Sk; Wed, 07 Feb 2018 16:04:41 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 9/9] Remove cleanups from solib.c Date: Wed, 7 Feb 2018 15:04:34 -0700 Message-Id: <20180207220434.6045-10-tom@tromey.com> In-Reply-To: <20180207220434.6045-1-tom@tromey.com> References: <20180207220434.6045-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1ejXpY-002nlZ-Sk X-Source-Sender: 174-29-33-254.hlrn.qwest.net (pokyo.Home) [174.29.33.254]:59168 X-Source-Auth: tom+tromey.com X-Email-Count: 10 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes a couple of cleanups from solib.c, replacing one with std::string and another with unique_xmalloc_ptr. 2018-02-07 Tom Tromey * solib.c (solib_find_1): Use std::string. (solib_bfd_fopen): Use unique_xmalloc_ptr. --- gdb/ChangeLog | 5 +++++ gdb/solib.c | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 84115ab5a9..ee1339b251 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2018-02-07 Tom Tromey + * solib.c (solib_find_1): Use std::string. + (solib_bfd_fopen): Use unique_xmalloc_ptr. + +2018-02-07 Tom Tromey + * build-id.c (build_id_to_debug_bfd): Use unique_xmalloc_ptr. 2018-02-07 Tom Tromey diff --git a/gdb/solib.c b/gdb/solib.c index 3dba5eaa8a..40fdfc59e6 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -155,8 +155,7 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) int found_file = -1; char *temp_pathname = NULL; const char *fskind = effective_target_file_system_kind (); - struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); - char *sysroot = gdb_sysroot; + const char *sysroot = gdb_sysroot; int prefix_len, orig_prefix_len; /* If the absolute prefix starts with "target:" but the filesystem @@ -174,12 +173,13 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1])) prefix_len--; + std::string sysroot_holder; if (prefix_len == 0) sysroot = NULL; else if (prefix_len != orig_prefix_len) { - sysroot = savestring (sysroot, prefix_len); - make_cleanup (xfree, sysroot); + sysroot_holder = std::string (sysroot, prefix_len); + sysroot = sysroot_holder.c_str (); } /* If we're on a non-DOS-based system, backslashes won't be @@ -251,7 +251,6 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) { if (fd != NULL) *fd = -1; - do_cleanups (old_chain); return temp_pathname; } @@ -300,8 +299,6 @@ solib_find_1 (const char *in_pathname, int *fd, int is_solib) } } - do_cleanups (old_chain); - /* We try to find the library in various ways. After each attempt, either found_file >= 0 and temp_pathname is a malloc'd string, or found_file < 0 and temp_pathname does not point to storage that @@ -480,7 +477,8 @@ solib_bfd_fopen (char *pathname, int fd) if (abfd == NULL) { - make_cleanup (xfree, pathname); + /* Arrange to free PATHNAME when the error is thrown. */ + gdb::unique_xmalloc_ptr free_pathname (pathname); error (_("Could not open `%s' as an executable file: %s"), pathname, bfd_errmsg (bfd_get_error ())); }