[PATCH v3 12/29] Call CloseHandle from ~windows_thread_info

Tom Tromey
2020-03-13T19:09:01Z

Add a destructor to windows_thread_info that calls CloseHandle.

gdb/ChangeLog
2020-03-13 Tom Tromey <tromey@adacore.com>

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

gdbserver/ChangeLog
2020-03-13 Tom Tromey <tromey@adacore.com>

* win32-low.c (delete_thread_info): Don't call CloseHandle.
---
gdb/ChangeLog | 6 ++++++
gdb/nat/windows-nat.c | 5 +++++
gdb/nat/windows-nat.h | 2 ++
gdbserver/ChangeLog | 4 ++++
gdbserver/win32-low.cc | 1 -
5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index 767ed8c192f..ca3e3087944 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 224ae5c536c..ccdf207140e 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -32,6 +32,8 @@ struct windows_thread_info
{
}

+ ~windows_thread_info ();
+
DISABLE_COPY_AND_ASSIGN (windows_thread_info);

/* Ensure that this thread has been suspended. */
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index 7cad640878f..c642d47764c 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -218,7 +218,6 @@ delete_thread_info (thread_info *thread)
windows_thread_info *th = (windows_thread_info *) thread_target_data (thread);

remove_thread (thread);
- CloseHandle (th->h);
delete th;
}

--
2.21.1