aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-02-06 13:00:40 -0700
committerTom Tromey <tom@tromey.com>2018-02-08 11:46:57 -0700
commit9a897d43f034544cd09292d0fb6fded7eb64ae8d (patch)
treef7e78bae3146839ac2020caa236166f7a289d5d8
parent58ef3771fbbdf7fd891fceefdd4bf2720c6c1ee7 (diff)
downloadgdb-9a897d43f034544cd09292d0fb6fded7eb64ae8d.zip
gdb-9a897d43f034544cd09292d0fb6fded7eb64ae8d.tar.gz
gdb-9a897d43f034544cd09292d0fb6fded7eb64ae8d.tar.bz2
Remove cleanups from solib.c
This removes a couple of cleanups from solib.c, replacing one with std::string and another with unique_xmalloc_ptr. 2018-02-08 Tom Tromey <tom@tromey.com> * solib.c (solib_find_1): Use std::string. (solib_bfd_fopen): Use unique_xmalloc_ptr.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/solib.c14
2 files changed, 11 insertions, 8 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d270de1..a5f0f20 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2018-02-08 Tom Tromey <tom@tromey.com>
+ * solib.c (solib_find_1): Use std::string.
+ (solib_bfd_fopen): Use unique_xmalloc_ptr.
+
+2018-02-08 Tom Tromey <tom@tromey.com>
+
* build-id.c (build_id_to_debug_bfd): Use unique_xmalloc_ptr.
2018-02-08 Tom Tromey <tom@tromey.com>
diff --git a/gdb/solib.c b/gdb/solib.c
index 3dba5ea..40fdfc5 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 ()));
}