From cef99c3837ddc910404593c4d06ed3890a76cc46 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Wed, 31 May 2017 01:28:50 +0300 Subject: [PATCH] [runtime] Don't make the domain id allocatable before we clear the domain (#4942) Otherwise, while we are clearing the domain, another domain might be created that has the same id as the current one. This would lead to crashes due to releasing of data from the newly created domain (ex gchandles). --- mono/metadata/domain.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c index 2e6a5217007..7a12a7f4f72 100644 --- a/mono/metadata/domain.c +++ b/mono/metadata/domain.c @@ -1037,10 +1037,6 @@ mono_domain_free (MonoDomain *domain, gboolean force) mono_debug_domain_unload (domain); - mono_appdomains_lock (); - appdomains_list [domain->domain_id] = NULL; - mono_appdomains_unlock (); - /* must do this early as it accesses fields and types */ if (domain->special_static_fields) { mono_alloc_special_static_data_free (domain->special_static_fields); @@ -1214,6 +1210,10 @@ mono_domain_free (MonoDomain *domain, gboolean force) mono_gc_deregister_root ((char*)&(domain->MONO_DOMAIN_FIRST_GC_TRACKED)); + mono_appdomains_lock (); + appdomains_list [domain->domain_id] = NULL; + mono_appdomains_unlock (); + /* FIXME: anything else required ? */ mono_gc_free_fixed (domain); -- 2.25.1