Fix WXORX issue in EEClass::Destruct (#79696)
authorJan Vorlicek <janvorli@microsoft.com>
Thu, 15 Dec 2022 14:06:03 +0000 (15:06 +0100)
committerGitHub <noreply@github.com>
Thu, 15 Dec 2022 14:06:03 +0000 (15:06 +0100)
While investigating failures of some coreclr tests when running in an
unloadable context, I've hit AV in EEClass::Destruct in one of the
tests. The reason is that we are missing ExecutableWriterHolder when
updating refCount on pDelegateEEClass->m_pInstRetBuffCallStub.

This change fixes it.

src/coreclr/vm/class.cpp

index bc0af49..b179bff 100644 (file)
@@ -162,7 +162,8 @@ void EEClass::Destruct(MethodTable * pOwningMT)
         }
         if (pDelegateEEClass->m_pInstRetBuffCallStub)
         {
-            pDelegateEEClass->m_pInstRetBuffCallStub->DecRef();
+            ExecutableWriterHolder<Stub> stubWriterHolder(pDelegateEEClass->m_pInstRetBuffCallStub, sizeof(Stub));
+            stubWriterHolder.GetRW()->DecRef();
         }
         // While m_pMultiCastInvokeStub is also a member,
         // it is owned by the m_pMulticastStubCache, not by the class