File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,22 @@ void ThreadLocalBlock::FreeTLM(SIZE_T i, BOOL isThreadShuttingdown)
5252 ThreadLocalModule::CollectibleDynamicEntry *entry = (ThreadLocalModule::CollectibleDynamicEntry*)pThreadLocalModule->m_pDynamicClassTable [k].m_pDynamicEntry ;
5353 PTR_LoaderAllocator pLoaderAllocator = entry->m_pLoaderAllocator ;
5454
55- if (entry->m_hGCStatics != NULL )
56- {
57- pLoaderAllocator->FreeHandle (entry->m_hGCStatics );
58- }
59- if (entry->m_hNonGCStatics != NULL )
55+ // LoaderAllocator may be collected when the thread is shutting down.
56+ // We enter coop mode to ensure that we get a valid value of the exposed object and
57+ // can safely clean up handles if it is not yet collected.
58+ GCX_COOP ();
59+
60+ LOADERALLOCATORREF loaderAllocator = pLoaderAllocator->GetExposedObject ();
61+ if (loaderAllocator != NULL )
6062 {
61- pLoaderAllocator->FreeHandle (entry->m_hNonGCStatics );
63+ if (entry->m_hGCStatics != NULL )
64+ {
65+ pLoaderAllocator->FreeHandle (entry->m_hGCStatics );
66+ }
67+ if (entry->m_hNonGCStatics != NULL )
68+ {
69+ pLoaderAllocator->FreeHandle (entry->m_hNonGCStatics );
70+ }
6271 }
6372 }
6473 delete pThreadLocalModule->m_pDynamicClassTable [k].m_pDynamicEntry ;
You can’t perform that action at this time.
0 commit comments