Skip to content

Commit 98ac457

Browse files
AaronRobinsonMSFTgithub-actions
authored andcommitted
Fix race condition in InteropSyncBlock for ComWrappers map.
1 parent 2f324b3 commit 98ac457

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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)