Make windows_thread_info::name a unique_xmalloc_ptr
authorTom Tromey <tromey@adacore.com>
Wed, 8 Apr 2020 20:33:35 +0000 (14:33 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 8 Apr 2020 20:47:58 +0000 (14:47 -0600)
This changes windows_thread_info::name to be a unique_xmalloc_ptr,
removing some manual memory management.

gdb/ChangeLog
2020-04-08  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
gdb/nat/windows-nat.h
gdb/windows-nat.c

index 6fce48c09a08ca24a6687243fa5a7e21532b5a03..a7ffec787645df2d319690865c6738c9e65f6168 100644 (file)
@@ -1,3 +1,10 @@
+2020-04-08  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.
+
 2020-04-08  Tom Tromey  <tromey@adacore.com>
 
        * windows-nat.c (thread_rec)
index 27fd7ed19dacb15b684e1c773921107935978110..543de895e77a8e5297d56a2502e932c3cd439634 100644 (file)
@@ -32,11 +32,6 @@ struct windows_thread_info
   {
   }
 
-  ~windows_thread_info ()
-  {
-    xfree (name);
-  }
-
   DISABLE_COPY_AND_ASSIGN (windows_thread_info);
 
   /* The Win32 thread identifier.  */
@@ -77,7 +72,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
index b7f21cb741d06319a90526f74eab47e1d4ea9f27..7fbc9a4d27d1d3c77d4619bd03392e1f846af242 100644 (file)
@@ -1414,8 +1414,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;
@@ -3394,7 +3393,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 ();
 }
 
 
This page took 0.033831 seconds and 4 git commands to generate.