[review] Make windows_thread_info::name a unique_xmalloc_ptr

Message ID gerrit.1572371871000.Ieb950249ddaf58ecc8faf98cc2b464d86c53fde3@gnutoolchain-gerrit.osci.io
State New, archived
Headers

Commit Message

Simon Marchi (Code Review) Oct. 29, 2019, 5:57 p.m. UTC
  Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/410
......................................................................

Make windows_thread_info::name a unique_xmalloc_ptr

This changes windows_thread_info::name to be a unique_xmalloc_ptr,
removing some manual memory management.

gdb/ChangeLog
2019-10-29  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.

Change-Id: Ieb950249ddaf58ecc8faf98cc2b464d86c53fde3
---
M gdb/ChangeLog
M gdb/nat/windows-nat.h
M gdb/windows-nat.c
3 files changed, 10 insertions(+), 9 deletions(-)
  

Comments

Simon Marchi (Code Review) Oct. 31, 2019, 7:06 p.m. UTC | #1
Simon Marchi has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/410
......................................................................


Patch Set 1: Code-Review+2
  
Simon Marchi (Code Review) Nov. 29, 2019, 6:01 p.m. UTC | #2
Pedro Alves has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/410
......................................................................


Patch Set 2: Code-Review+2
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c83fb0e..92f77fc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@ 
 2019-10-29  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.
+
+2019-10-29  Tom Tromey  <tromey@adacore.com>
+
 	* windows-nat.c (thread_rec)
 	(windows_nat_target::fetch_registers): Update.
 	* nat/windows-nat.h (struct windows_thread_info) <suspended>:
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 0cfc071..06c6486 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -30,11 +30,6 @@ 
   {
   }
 
-  ~windows_thread_info ()
-  {
-    xfree (name);
-  }
-
   DISABLE_COPY_AND_ASSIGN (windows_thread_info);
 
   /* The Win32 thread identifier.  */
@@ -68,7 +63,7 @@ 
   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 75d61cf..12a69bb 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1261,8 +1261,7 @@ 
 	      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 @@ 
 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 ();
 }