[7/9] Make windows_thread_info::name a unique_xmalloc_ptr

Message ID 20191014161520.13150-8-tromey@adacore.com
State New, archived
Headers

Commit Message

Tom Tromey Oct. 14, 2019, 4:15 p.m. UTC
  This changes windows_thread_info::name to be a unique_xmalloc_ptr,
removing some manual memory management.

2019-10-14  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (handle_exception)
	(windows_nat_target::thread_name): Update.
	* nat/windows-nat.h (windows_thread_info): Remove destructor.
	<name>: Now unique_xmalloc_ptr.
---
 gdb/ChangeLog         | 7 +++++++
 gdb/nat/windows-nat.h | 7 +------
 gdb/windows-nat.c     | 5 ++---
 3 files changed, 10 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 0cfc0716f26..06c6486c0c0 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -30,11 +30,6 @@  struct windows_thread_info
   {
   }
 
-  ~windows_thread_info ()
-  {
-    xfree (name);
-  }
-
   DISABLE_COPY_AND_ASSIGN (windows_thread_info);
 
   /* The Win32 thread identifier.  */
@@ -68,7 +63,7 @@  struct windows_thread_info
   bool reload_context = false;
 
   /* The name of the thread, allocated by xmalloc.  */
-  char *name = nullptr;
+  gdb::unique_xmalloc_ptr<char> name;
 };
 
 #endif
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index b38ff402cb5..3a526e504e4 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1261,8 +1261,7 @@  handle_exception (struct target_waitstatus *ourstatus)
 	      if (thread_name_len > 0)
 		{
 		  thread_name.get ()[thread_name_len - 1] = '\0';
-		  xfree (named_thread->name);
-		  named_thread->name = thread_name.release ();
+		  named_thread->name = std::move (thread_name);
 		}
 	    }
 	  ourstatus->value.sig = GDB_SIGNAL_TRAP;
@@ -3000,7 +2999,7 @@  windows_nat_target::get_ada_task_ptid (long lwp, long thread)
 const char *
 windows_nat_target::thread_name (struct thread_info *thr)
 {
-  return thread_rec (thr->ptid.tid (), 0)->name;
+  return thread_rec (thr->ptid.tid (), 0)->name.get ();
 }