Fix for double CloseHandle() on AppDomain unload
authorNiklas Therning <niklas@therning.org>
Mon, 29 Aug 2016 12:00:48 +0000 (14:00 +0200)
committerNiklas Therning <niklas@therning.org>
Mon, 29 Aug 2016 12:00:48 +0000 (14:00 +0200)
commit2d407e62e6b2b6172f763211b80561e0293cd0d9
treedee14965e199c7d24b0f1ea1b043b3ee658420c2
parentdcd650d6fc59817b1efd6fc088ac41ce304a41c2
Fix for double CloseHandle() on AppDomain unload

When AppDomain.Unload() is called a new thread is created and attached. When
this thread is done the thread handle is immediately closed using
CloseHandle() but the same handle is also passed to CloseHandle() later on by
the InternalThread destructor. On the second CloseHandle() call Windows will
abort the process with an "Invalid handle" error.

This patch removes the CloseHandle() calls in mono_domain_try_unload() which
is called by AppDomain.Unload(). The patch also wires up some more functions
in mono/utils/mono-threads-windows.c to set the MonoThreadInfo.handle field to
NULL when a thread has exited.
mono/metadata/appdomain.c
mono/utils/mono-threads-windows.c