[RFA,2/3] Use unique_xmalloc_ptr in darwin_current_sos

Message ID 20180527210057.12554-3-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey May 27, 2018, 9 p.m. UTC
  This changes darwin_current_sos to use unique_xmalloc_ptr rather than
a cleanup.

ChangeLog
2018-05-27  Tom Tromey  <tom@tromey.com>

	* solib-darwin.c (darwin_current_sos): Use unique_xmalloc_ptr.
---
 gdb/ChangeLog      |  4 ++++
 gdb/solib-darwin.c | 13 ++++---------
 2 files changed, 8 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 557fb156b22..d74ea2af158 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -263,8 +263,6 @@  darwin_current_sos (void)
       unsigned long hdr_val;
       gdb::unique_xmalloc_ptr<char> file_path;
       int errcode;
-      struct so_list *newobj;
-      struct cleanup *old_chain;
 
       /* Read image info from inferior.  */
       if (target_read_memory (iinfo, buf, image_info_size))
@@ -293,8 +291,7 @@  darwin_current_sos (void)
 	break;
 
       /* Create and fill the new so_list element.  */
-      newobj = XCNEW (struct so_list);
-      old_chain = make_cleanup (xfree, newobj);
+      gdb::unique_xmalloc_ptr<struct so_list> newobj (XCNEW (struct so_list));
 
       lm_info_darwin *li = new lm_info_darwin;
       newobj->lm_info = li;
@@ -305,12 +302,10 @@  darwin_current_sos (void)
       li->lm_addr = load_addr;
 
       if (head == NULL)
-	head = newobj;
+	head = newobj.get ();
       else
-	tail->next = newobj;
-      tail = newobj;
-
-      discard_cleanups (old_chain);
+	tail->next = newobj.get ();
+      tail = newobj.release ();
     }
 
   return head;