Skip to content

Commit

Permalink
[release/6.0] Fix a memory leak in runtime interop stubs when using a…
Browse files Browse the repository at this point in the history
…n array of structs of types that use old-style managed marshalers
  • Loading branch information
jkoritzinsky authored and github-actions committed Oct 6, 2023
1 parent 7ee35b9 commit 9d8610c
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/coreclr/vm/ilmarshalers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3138,39 +3138,33 @@ class ILMngdMarshaler : public ILMarshaler
void EmitClearNative(ILCodeStream* pslILEmit) override
{
WRAPPER_NO_CONTRACT;
ILCodeLabel* pNoManagedValueLabel = nullptr;
if (IsFieldMarshal(m_dwMarshalFlags))
{
pNoManagedValueLabel = pslILEmit->NewCodeLabel();
ILCodeLabel* pHasManagedValueLabel = pslILEmit->NewCodeLabel();
pslILEmit->EmitLDARG(StructMarshalStubs::MANAGED_STRUCT_ARGIDX);
pslILEmit->EmitBRFALSE(pNoManagedValueLabel);
pslILEmit->EmitBRTRUE(pHasManagedValueLabel);
pslILEmit->EmitLDARG(StructMarshalStubs::MANAGED_STRUCT_ARGIDX);
EmitStoreManagedHomeAddr(pslILEmit);
pslILEmit->EmitLabel(pHasManagedValueLabel);
}

EmitCallMngdMarshalerMethod(pslILEmit, GetClearNativeMethod());

if (IsFieldMarshal(m_dwMarshalFlags))
{
pslILEmit->EmitLabel(pNoManagedValueLabel);
}
}

void EmitClearNativeContents(ILCodeStream* pslILEmit) override
{
WRAPPER_NO_CONTRACT;
ILCodeLabel* pNoManagedValueLabel = nullptr;
if (IsFieldMarshal(m_dwMarshalFlags))
{
pNoManagedValueLabel = pslILEmit->NewCodeLabel();
ILCodeLabel* pHasManagedValueLabel = pslILEmit->NewCodeLabel();
pslILEmit->EmitLDARG(StructMarshalStubs::MANAGED_STRUCT_ARGIDX);
pslILEmit->EmitBRFALSE(pNoManagedValueLabel);
pslILEmit->EmitBRTRUE(pHasManagedValueLabel);
pslILEmit->EmitLDARG(StructMarshalStubs::MANAGED_STRUCT_ARGIDX);
EmitStoreManagedHomeAddr(pslILEmit);
pslILEmit->EmitLabel(pHasManagedValueLabel);
}

EmitCallMngdMarshalerMethod(pslILEmit, GetClearNativeContentsMethod());

if (IsFieldMarshal(m_dwMarshalFlags))
{
pslILEmit->EmitLabel(pNoManagedValueLabel);
}
}

bool NeedsClearCLR() override
Expand Down

0 comments on commit 9d8610c

Please sign in to comment.