[runtime] Don't make the domain id allocatable before we clear the domain (#4942)
authorVlad Brezae <brezaevlad@gmail.com>
Tue, 30 May 2017 22:28:50 +0000 (01:28 +0300)
committerGitHub <noreply@github.com>
Tue, 30 May 2017 22:28:50 +0000 (01:28 +0300)
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

index 2e6a52170078f5487e79fb00c2df5e32508b741b..7a12a7f4f727df945ec2a21815c6dbece75bce0b 100644 (file)
@@ -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);