Patchwork [review,v2] Make windows_thread_info::name a unique_xmalloc_ptr

login
register
mail settings
Submitter Simon Marchi (Code Review)
Date Nov. 26, 2019, 5:11 p.m.
Message ID <20191126171131.3284128174@gnutoolchain-gerrit.osci.io>
Download mbox | patch
Permalink /patch/36215/
State New
Headers show

Comments

Simon Marchi (Code Review) - Nov. 26, 2019, 5:11 p.m.
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-11-26  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(-)

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e48f650..621f890 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@ 
 2019-11-26  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-11-26  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 e5d7e63..db21ca7 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.  */
@@ -69,7 +64,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 4898fba..f283495 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;
@@ -3001,7 +3000,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 ();
 }