From 9d59b970b5aa6c1489f67c4cbd401fca069da6a0 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Thu, 15 Dec 2022 11:36:18 +0100 Subject: [PATCH] Fix WXORX issue in EEClass::Destruct 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/class.cpp b/src/coreclr/vm/class.cpp index fd6053c64bfb5..6558f7dec2e18 100644 --- a/src/coreclr/vm/class.cpp +++ b/src/coreclr/vm/class.cpp @@ -162,7 +162,8 @@ void EEClass::Destruct(MethodTable * pOwningMT) } if (pDelegateEEClass->m_pInstRetBuffCallStub) { - pDelegateEEClass->m_pInstRetBuffCallStub->DecRef(); + ExecutableWriterHolder 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