public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 9/9] Remove cleanups from solib.c
Date: Wed, 07 Feb 2018 22:04:00 -0000	[thread overview]
Message-ID: <20180207220434.6045-10-tom@tromey.com> (raw)
In-Reply-To: <20180207220434.6045-1-tom@tromey.com>

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  <tom@tromey.com>

	* 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  <tom@tromey.com>
 
+	* solib.c (solib_find_1): Use std::string.
+	(solib_bfd_fopen): Use unique_xmalloc_ptr.
+
+2018-02-07  Tom Tromey  <tom@tromey.com>
+
 	* build-id.c (build_id_to_debug_bfd): Use unique_xmalloc_ptr.
 
 2018-02-07  Tom Tromey  <tom@tromey.com>
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<char> free_pathname (pathname);
       error (_("Could not open `%s' as an executable file: %s"),
 	     pathname, bfd_errmsg (bfd_get_error ()));
     }
-- 
2.13.6

  parent reply	other threads:[~2018-02-07 22:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-07 22:04 [RFA 0/9] more cleanup removal Tom Tromey
2018-02-07 22:04 ` [RFA 6/9] Remove cleanups from macro_define_command Tom Tromey
2018-02-07 22:04 ` [RFA 5/9] Use std::string in maybe_expand Tom Tromey
2018-02-07 22:04 ` [RFA 7/9] Use std::vector in find_source_lines Tom Tromey
2018-02-09 13:00   ` Tom Tromey
2018-02-09 13:11     ` Pedro Alves
2018-02-07 22:04 ` [RFA 1/9] Remove a cleanup from gdbserver Tom Tromey
2018-02-07 22:04 ` [RFA 8/9] Use unique_xmalloc_ptr in build_id_to_debug_bfd Tom Tromey
2018-02-07 22:04 ` Tom Tromey [this message]
2018-02-07 22:04 ` [RFA 3/9] Return unique_xmalloc_ptr from macro scope functions Tom Tromey
2018-02-07 22:04 ` [RFA 4/9] Class-ify macro_buffer Tom Tromey
2018-02-07 22:04 ` [RFA 2/9] Remove make_cleanup_restore_current_thread from gdbserver Tom Tromey
2018-02-08 16:42 ` [RFA 0/9] more cleanup removal Pedro Alves
2018-02-08 18:45   ` Tom Tromey

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=20180207220434.6045-10-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).