From: Vlad Brezae Date: Tue, 30 May 2017 22:28:50 +0000 (+0300) Subject: [runtime] Don't make the domain id allocatable before we clear the domain (#4942) X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=cef99c3837ddc910404593c4d06ed3890a76cc46 [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). --- 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);