Skip to content

Commit f3b925d

Browse files
Fix race condition in InteropSyncBlock for ComWrappers map. (#65214)
1 parent 5fbd81a commit f3b925d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/coreclr/vm/syncblk.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ class InteropSyncBlockInfo
621621
{
622622
LIMITED_METHOD_CONTRACT;
623623
ZeroMemory(this, sizeof(InteropSyncBlockInfo));
624+
625+
#if defined(FEATURE_COMWRAPPERS)
626+
// The GC thread does enumerate these objects so add CRST_UNSAFE_COOPGC.
627+
m_managedObjectComWrapperLock.Init(CrstManagedObjectWrapperMap, CRST_UNSAFE_COOPGC);
628+
#endif // FEATURE_COMWRAPPERS
624629
}
625630
#ifndef DACCESS_COMPILE
626631
~InteropSyncBlockInfo();
@@ -799,8 +804,6 @@ class InteropSyncBlockInfo
799804
if (FastInterlockCompareExchangePointer((ManagedObjectComWrapperByIdMap**)&m_managedObjectComWrapperMap, (ManagedObjectComWrapperByIdMap *)map, NULL) == NULL)
800805
{
801806
map.SuppressRelease();
802-
// The GC thread does enumerate these objects so add CRST_UNSAFE_COOPGC.
803-
m_managedObjectComWrapperLock.Init(CrstManagedObjectWrapperMap, CRST_UNSAFE_COOPGC);
804807
}
805808

806809
_ASSERTE(m_managedObjectComWrapperMap != NULL);

0 commit comments

Comments
 (0)