[threads] Destroy thread->suspended before removing the GC root to thread (#4133)
authorLudovic Henry <ludovic@xamarin.com>
Mon, 12 Dec 2016 23:57:07 +0000 (18:57 -0500)
committerGitHub <noreply@github.com>
Mon, 12 Dec 2016 23:57:07 +0000 (18:57 -0500)
mono/metadata/threads.c

index 953a2315008f047a7dced9b39f53a9d0f218a3f2..84649c6f9de5243e23b84a97be1118379845d7d6 100644 (file)
@@ -1113,6 +1113,11 @@ mono_thread_detach_internal (MonoInternalThread *thread)
        ref_stack_destroy (thread->appdomain_refs);
        thread->appdomain_refs = NULL;
 
+       g_assert (thread->suspended);
+       mono_os_event_destroy (thread->suspended);
+       g_free (thread->suspended);
+       thread->suspended = NULL;
+
        if (mono_thread_cleanup_fn)
                mono_thread_cleanup_fn (thread_get_tid (thread));
 
@@ -1121,11 +1126,6 @@ mono_thread_detach_internal (MonoInternalThread *thread)
                thread->thread_pinning_ref = NULL;
        }
 
-       g_assert (thread->suspended);
-       mono_os_event_destroy (thread->suspended);
-       g_free (thread->suspended);
-       thread->suspended = NULL;
-
 done:
        SET_CURRENT_OBJECT (NULL);
        mono_domain_unset ();