Close unused diagnostic server thread handle (dotnet/coreclr#27141)
authorJan Kotas <jkotas@microsoft.com>
Fri, 11 Oct 2019 14:13:10 +0000 (07:13 -0700)
committerGitHub <noreply@github.com>
Fri, 11 Oct 2019 14:13:10 +0000 (07:13 -0700)
Fixes dotnet/coreclr#27135

Commit migrated from https://github.com/dotnet/coreclr/commit/d8bbcc485be92b2feaf392eb750b7b523a872b6c

src/coreclr/src/vm/diagnosticserver.cpp
src/coreclr/src/vm/diagnosticserver.h

index 53bc860..818f8b7 100644 (file)
@@ -21,7 +21,6 @@
 
 IpcStream::DiagnosticsIpc *DiagnosticServer::s_pIpc = nullptr;
 Volatile<bool> DiagnosticServer::s_shuttingDown(false);
-HANDLE DiagnosticServer::s_hServerThread = INVALID_HANDLE_VALUE;
 
 DWORD WINAPI DiagnosticServer::DiagnosticsServerThread(LPVOID)
 {
@@ -147,7 +146,7 @@ bool DiagnosticServer::Initialize()
             auto_trace_launch();
 #endif
             DWORD dwThreadId = 0;
-            s_hServerThread = ::CreateThread( // TODO: Is it correct to have this "lower" level call here?
+            HANDLE hServerThread = ::CreateThread( // TODO: Is it correct to have this "lower" level call here?
                 nullptr,                     // no security attribute
                 0,                           // default stack size
                 DiagnosticsServerThread,     // thread proc
@@ -155,7 +154,7 @@ bool DiagnosticServer::Initialize()
                 0,                           // not suspended
                 &dwThreadId);                // returns thread ID
 
-            if (s_hServerThread == NULL)
+            if (hServerThread == NULL)
             {
                 delete s_pIpc;
                 s_pIpc = nullptr;
@@ -169,6 +168,8 @@ bool DiagnosticServer::Initialize()
             }
             else
             {
+                ::CloseHandle(hServerThread);
+
 #ifdef FEATURE_AUTO_TRACE
                 auto_trace_wait();
 #endif
index f196c9c..393fbda 100644 (file)
@@ -48,7 +48,6 @@ public:
 private:
     static IpcStream::DiagnosticsIpc *s_pIpc;
     static Volatile<bool> s_shuttingDown;
-    static HANDLE s_hServerThread;
 };
 
 #endif // FEATURE_PERFTRACING