[review] Call CloseHandle from ~windows_thread_info

Message ID gerrit.1572371871000.I640a0e770e103a5f44754ea8a758123807790d04@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/+/415
......................................................................

Call CloseHandle from ~windows_thread_info

Add a destructor to windows_thread_info that calls CloseHandle.

Change-Id: I4bae7f2551aa55be2bc5bd93d566a5c2e369247f

gdb/ChangeLog
2019-10-29  Tom Tromey  <tromey@adacore.com>

	* nat/windows-nat.h (struct windows_thread_info): Declare
	destructor.
	* nat/windows-nat.c (~windows_thread_info): New.

gdb/gdbserver/ChangeLog
2019-10-29  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (delete_thread_info): Don't call CloseHandle.

Change-Id: I640a0e770e103a5f44754ea8a758123807790d04
---
M gdb/ChangeLog
M gdb/gdbserver/ChangeLog
M gdb/gdbserver/win32-low.c
M gdb/nat/windows-nat.c
M gdb/nat/windows-nat.h
5 files changed, 17 insertions(+), 1 deletion(-)
  

Comments

Simon Marchi (Code Review) Nov. 26, 2019, 10:51 p.m. UTC | #1
Luis Machado has posted comments on this change.

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


Patch Set 1: Code-Review+1

LGTM
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ecabb25..2a63867 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@ 
 2019-10-29  Tom Tromey  <tromey@adacore.com>
 
+	* nat/windows-nat.h (struct windows_thread_info): Declare
+	destructor.
+	* nat/windows-nat.c (~windows_thread_info): New.
+
+2019-10-29  Tom Tromey  <tromey@adacore.com>
+
 	PR gdb/22992
 	* windows-nat.c (current_event): Update comment.
 	(last_wait_event, desired_stop_thread_id): New globals.
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 2f31755..fb1c7bc 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,9 @@ 
 2019-10-29  Tom Tromey  <tromey@adacore.com>
 
+	* win32-low.c (delete_thread_info): Don't call CloseHandle.
+
+2019-10-29  Tom Tromey  <tromey@adacore.com>
+
 	* win32-low.c (win32_require_context, suspend_one_thread): Use
 	windows_thread_info::suspend.
 	(continue_one_thread): Use windows_thread_info::resume.
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 59749f0..9d69af7 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -219,7 +219,6 @@ 
   windows_thread_info *th = (windows_thread_info *) thread_target_data (thread);
 
   remove_thread (thread);
-  CloseHandle (th->h);
   delete th;
 }
 
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index a98ff42..2a0e3a3 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -19,6 +19,11 @@ 
 #include "gdbsupport/common-defs.h"
 #include "nat/windows-nat.h"
 
+windows_thread_info::~windows_thread_info ()
+{
+  CloseHandle (h);
+}
+
 void
 windows_thread_info::suspend ()
 {
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index b51279b..d1bdea2 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -32,6 +32,8 @@ 
   {
   }
 
+  ~windows_thread_info ();
+
   DISABLE_COPY_AND_ASSIGN (windows_thread_info);
 
   /* Ensure that this thread has been suspended.  */