From 4ecef5f32b3a08967e77c28d0fab04a7a4290c21 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 3 Nov 2022 14:25:34 -0700 Subject: [PATCH] Free LOADERHANDLE DispatchMemberInfo dtor (#77570) This is a regression from NETFX with the introduction of collectable assemblies in .NET Core 3.1 (dotnet/coreclr#20919). Co-authored-by: Aaron Robinson --- src/coreclr/vm/dispatchinfo.cpp | 30 ++++++++++++------------------ src/coreclr/vm/dispatchinfo.h | 5 +---- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/coreclr/vm/dispatchinfo.cpp b/src/coreclr/vm/dispatchinfo.cpp index 8d970bca9afe8..59aa001f2d417 100644 --- a/src/coreclr/vm/dispatchinfo.cpp +++ b/src/coreclr/vm/dispatchinfo.cpp @@ -66,7 +66,7 @@ typedef int (__cdecl *UnicodeStringCompareFuncPtr)(const WCHAR *, const WCHAR *) //-------------------------------------------------------------------------------- // The DispatchMemberInfo class implementation. -DispatchMemberInfo::DispatchMemberInfo(DispatchInfo *pDispInfo, DISPID DispID, SString& strName, OBJECTREF MemberInfoObj) +DispatchMemberInfo::DispatchMemberInfo(DispatchInfo *pDispInfo, DISPID DispID, SString& strName) : m_DispID(DispID) , m_hndMemberInfo(NULL) , m_apParamMarshaler(NULL) @@ -82,7 +82,7 @@ DispatchMemberInfo::DispatchMemberInfo(DispatchInfo *pDispInfo, DISPID DispID, S , m_pDispInfo(pDispInfo) , m_bLastParamOleVarArg(FALSE) { - WRAPPER_NO_CONTRACT; // Calls to CreateHandle, above, means not a leaf contract + WRAPPER_NO_CONTRACT; } void DispatchMemberInfo::Neuter() @@ -137,6 +137,9 @@ DispatchMemberInfo::~DispatchMemberInfo() if (m_pParamInOnly) delete [] m_pParamInOnly; + if (m_hndMemberInfo) + m_pDispInfo->GetLoaderAllocator()->FreeHandle(m_hndMemberInfo); + // Clear the name of the member. m_strName.Clear(); } @@ -335,6 +338,11 @@ PTRARRAYREF DispatchMemberInfo::GetParameters() return ParamArray; } +OBJECTREF DispatchMemberInfo::GetMemberInfoObject() +{ + return m_pDispInfo->GetLoaderAllocator()->GetHandleValue(m_hndMemberInfo); +} + void DispatchMemberInfo::MarshalParamNativeToManaged(int iParam, VARIANT *pSrcVar, OBJECTREF *pDestObj) { CONTRACTL @@ -1013,19 +1021,6 @@ void DispatchMemberInfo::SetUpDispParamAttributes(int iParam, MarshalInfo* Info) m_pParamInOnly[iParam] = ( Info->IsIn() && !Info->IsOut() ); } -#ifndef DACCESS_COMPILE -OBJECTREF DispatchMemberInfo::GetMemberInfoObject() -{ - return m_pDispInfo->GetLoaderAllocator()->GetHandleValue(m_hndMemberInfo); -} - -void DispatchMemberInfo::ClearMemberInfoObject() -{ - m_pDispInfo->GetLoaderAllocator()->SetHandleValue(m_hndMemberInfo, NULL); -} -#endif // DACCESS_COMPILE - - //-------------------------------------------------------------------------------- // The DispatchInfo class implementation. @@ -1162,7 +1157,7 @@ DispatchMemberInfo* DispatchInfo::CreateDispatchMemberInfoInstance(DISPID DispID } CONTRACT_END; - DispatchMemberInfo* pInfo = new DispatchMemberInfo(this, DispID, strMemberName, MemberInfoObj); + DispatchMemberInfo* pInfo = new DispatchMemberInfo(this, DispID, strMemberName); pInfo->SetHandle(GetLoaderAllocator()->AllocateHandle(MemberInfoObj)); RETURN pInfo; @@ -3291,8 +3286,7 @@ DispatchMemberInfo* DispatchExInfo::CreateDispatchMemberInfoInstance(DISPID Disp } CONTRACT_END; - DispatchMemberInfo* pInfo = new DispatchMemberInfo(this, DispID, strMemberName, MemberInfoObj); - + DispatchMemberInfo* pInfo = new DispatchMemberInfo(this, DispID, strMemberName); pInfo->SetHandle(GetLoaderAllocator()->AllocateHandle(MemberInfoObj)); RETURN pInfo; diff --git a/src/coreclr/vm/dispatchinfo.h b/src/coreclr/vm/dispatchinfo.h index 1ee7b71f607ab..dfe3d0facc411 100644 --- a/src/coreclr/vm/dispatchinfo.h +++ b/src/coreclr/vm/dispatchinfo.h @@ -54,7 +54,7 @@ enum CultureAwareStates // This structure represents a dispatch member. struct DispatchMemberInfo { - DispatchMemberInfo(DispatchInfo *pDispInfo, DISPID DispID, SString& strName, OBJECTREF MemberInfoObj); + DispatchMemberInfo(DispatchInfo *pDispInfo, DISPID DispID, SString& strName); ~DispatchMemberInfo(); // Helper method to ensure the entry is initialized. @@ -148,10 +148,7 @@ struct DispatchMemberInfo return m_bRequiresManagedCleanup; } -#ifndef DACCESS_COMPILE OBJECTREF GetMemberInfoObject(); - void ClearMemberInfoObject(); -#endif // DACCESS_COMPILE // Parameter marshaling methods. void MarshalParamNativeToManaged(int iParam, VARIANT *pSrcVar, OBJECTREF *pDestObj);