Patchwork [RFA,8/9] Use unique_xmalloc_ptr in build_id_to_debug_bfd

login
register
mail settings
Submitter Tom Tromey
Date Feb. 7, 2018, 10:04 p.m.
Message ID <20180207220434.6045-9-tom@tromey.com>
Download mbox | patch
Permalink /patch/25869/
State New
Headers show

Comments

Tom Tromey - Feb. 7, 2018, 10:04 p.m.
This changes build_id_to_debug_bfd to use a unique_xmalloc_ptr,
removing a cleanup.

2018-02-07  Tom Tromey  <tom@tromey.com>

	* build-id.c (build_id_to_debug_bfd): Use unique_xmalloc_ptr.
---
 gdb/ChangeLog  | 4 ++++
 gdb/build-id.c | 9 +++------
 2 files changed, 7 insertions(+), 6 deletions(-)

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8bd04e47c7..84115ab5a9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@ 
 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>
+
 	* source.c (find_source_lines): Use std::vector.
 
 2018-02-07  Tom Tromey  <tom@tromey.com>
diff --git a/gdb/build-id.c b/gdb/build-id.c
index 945da4f3cf..685a2b0370 100644
--- a/gdb/build-id.c
+++ b/gdb/build-id.c
@@ -95,8 +95,6 @@  build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
       const gdb_byte *data = build_id;
       size_t size = build_id_len;
       char *s;
-      char *filename = NULL;
-      struct cleanup *inner;
 
       memcpy (link, debugdir, debugdir_len);
       s = &link[debugdir_len];
@@ -116,16 +114,15 @@  build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
 	printf_unfiltered (_("  Trying %s\n"), link);
 
       /* lrealpath() is expensive even for the usually non-existent files.  */
+      gdb::unique_xmalloc_ptr<char> filename;
       if (access (link, F_OK) == 0)
-	filename = lrealpath (link);
+	filename.reset (lrealpath (link));
 
       if (filename == NULL)
 	continue;
 
       /* We expect to be silent on the non-existing files.  */
-      inner = make_cleanup (xfree, filename);
-      abfd = gdb_bfd_open (filename, gnutarget, -1);
-      do_cleanups (inner);
+      abfd = gdb_bfd_open (filename.get (), gnutarget, -1);
 
       if (abfd == NULL)
 	continue;