Skip to content

Commit

Permalink
Free LOADERHANDLE DispatchMemberInfo dtor (#77570)
Browse files Browse the repository at this point in the history
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 <arobins@microsoft.com>
  • Loading branch information
github-actions[bot] and AaronRobinsonMSFT authored Nov 3, 2022
1 parent bdff556 commit 4ecef5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
30 changes: 12 additions & 18 deletions src/coreclr/vm/dispatchinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/vm/dispatchinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4ecef5f

Please sign in to comment.