Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free temporary enums on failure #50471

Merged
merged 2 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/coreclr/md/compiler/assemblymd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ STDMETHODIMP RegMeta::EnumExportedTypes( // S_OK or error
BEGIN_ENTRYPOINT_NOTHROW;

HENUMInternal **ppmdEnum = reinterpret_cast<HENUMInternal **> (phEnum);
HENUMInternal *pEnum;
HENUMInternal *pEnumTmp = 0;

LOG((LOGMD, "MD RegMeta::EnumExportedTypes(%#08x, %#08x, %#08x, %#08x)\n",
phEnum, rExportedTypes, cMax, pcTokens));
Expand All @@ -460,7 +460,7 @@ STDMETHODIMP RegMeta::EnumExportedTypes( // S_OK or error
if (pMiniMd->HasDelete() &&
((m_OptionValue.m_ImportOption & MDImportOptionAllExportedTypes) == 0))
{
IfFailGo( HENUMInternal::CreateDynamicArrayEnum( mdtExportedType, &pEnum) );
IfFailGo( HENUMInternal::CreateDynamicArrayEnum( mdtExportedType, &pEnumTmp) );

// add all Types to the dynamic array if name is not _Delete
for (ULONG index = 1; index <= pMiniMd->getCountExportedTypes(); index ++ )
Expand All @@ -473,7 +473,7 @@ STDMETHODIMP RegMeta::EnumExportedTypes( // S_OK or error
{
continue;
}
IfFailGo( HENUMInternal::AddElementToEnum(pEnum, TokenFromRid(index, mdtExportedType) ) );
IfFailGo( HENUMInternal::AddElementToEnum(pEnumTmp, TokenFromRid(index, mdtExportedType) ) );
}
}
else
Expand All @@ -483,19 +483,19 @@ STDMETHODIMP RegMeta::EnumExportedTypes( // S_OK or error
mdtExportedType,
1,
pMiniMd->getCountExportedTypes() + 1,
&pEnum) );
&pEnumTmp) );
}

// set the output parameter.
*ppmdEnum = pEnum;
*ppmdEnum = pEnumTmp;
pEnumTmp = 0;
}
else
pEnum = *ppmdEnum;

// we can only fill the minimum of what the caller asked for or what we have left.
IfFailGo(HENUMInternal::EnumWithCount(pEnum, cMax, rExportedTypes, pcTokens));
IfFailGo(HENUMInternal::EnumWithCount(*ppmdEnum, cMax, rExportedTypes, pcTokens));
ErrExit:
HENUMInternal::DestroyEnumIfEmpty(ppmdEnum);
HENUMInternal::DestroyEnum(pEnumTmp);

STOP_MD_PERF(EnumExportedTypes);
END_ENTRYPOINT_NOTHROW;
Expand Down
26 changes: 14 additions & 12 deletions src/coreclr/md/compiler/custattr_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
HENUMInternal **ppmdEnum = reinterpret_cast<HENUMInternal **> (phEnum);
RID ridStart;
RID ridEnd;
HENUMInternal *pEnum = *ppmdEnum;
HENUMInternal *pEnumTmp = 0;
CustomAttributeRec *pRec;
ULONG index;

Expand All @@ -117,7 +117,7 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
START_MD_PERF();
LOCKREAD();

if ( pEnum == 0 )
if ( *ppmdEnum == 0 )
{
// instantiating a new ENUM
CMiniMdRW *pMiniMd = &(m_pStgdb->m_MiniMd);
Expand All @@ -126,7 +126,7 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
// Does caller want all custom Values?
if (IsNilToken(tk))
{
IfFailGo( HENUMInternal::CreateSimpleEnum(mdtCustomAttribute, 1, pMiniMd->getCountCustomAttributes()+1, &pEnum) );
IfFailGo( HENUMInternal::CreateSimpleEnum(mdtCustomAttribute, 1, pMiniMd->getCountCustomAttributes()+1, &pEnumTmp) );
}
else
{ // Scope by some object.
Expand All @@ -138,20 +138,20 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
if (IsNilToken(tkType))
{
// Simple enumerator for object's entire list.
IfFailGo( HENUMInternal::CreateSimpleEnum( mdtCustomAttribute, ridStart, ridEnd, &pEnum) );
IfFailGo( HENUMInternal::CreateSimpleEnum( mdtCustomAttribute, ridStart, ridEnd, &pEnumTmp) );
}
else
{
// Dynamic enumerator for subsetted list.

IfFailGo( HENUMInternal::CreateDynamicArrayEnum( mdtCustomAttribute, &pEnum) );
IfFailGo( HENUMInternal::CreateDynamicArrayEnum( mdtCustomAttribute, &pEnumTmp) );

for (index = ridStart; index < ridEnd; index ++ )
{
IfFailGo(pMiniMd->GetCustomAttributeRecord(index, &pRec));
if (tkType == pMiniMd->getTypeOfCustomAttribute(pRec))
{
IfFailGo( HENUMInternal::AddElementToEnum(pEnum, TokenFromRid(index, mdtCustomAttribute) ) );
IfFailGo( HENUMInternal::AddElementToEnum(pEnumTmp, TokenFromRid(index, mdtCustomAttribute) ) );
}
}
}
Expand All @@ -172,7 +172,7 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
// Hash the data.
iHash = pMiniMd->HashCustomAttribute(tk);

IfFailGo( HENUMInternal::CreateDynamicArrayEnum( mdtCustomAttribute, &pEnum) );
IfFailGo( HENUMInternal::CreateDynamicArrayEnum( mdtCustomAttribute, &pEnumTmp) );

// Go through every entry in the hash chain looking for ours.
for (p = pHashTable->FindFirst(iHash, pos);
Expand All @@ -189,7 +189,7 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
if (IsNilToken(tkType) || tkType == tkTypeTmp)
{
// compare the blob value
IfFailGo( HENUMInternal::AddElementToEnum(pEnum, TokenFromRid(p->tok, mdtCustomAttribute )) );
IfFailGo( HENUMInternal::AddElementToEnum(pEnumTmp, TokenFromRid(p->tok, mdtCustomAttribute )) );
}
}
}
Expand All @@ -203,30 +203,32 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
ridStart = 1;
ridEnd = pMiniMd->getCountCustomAttributes() + 1;

IfFailGo( HENUMInternal::CreateDynamicArrayEnum( mdtCustomAttribute, &pEnum) );
IfFailGo( HENUMInternal::CreateDynamicArrayEnum( mdtCustomAttribute, &pEnumTmp) );

for (index = ridStart; index < ridEnd; index ++ )
{
IfFailGo(pMiniMd->GetCustomAttributeRecord(index, &pRec));
if ( tk == pMiniMd->getParentOfCustomAttribute(pRec) &&
(tkType == pMiniMd->getTypeOfCustomAttribute(pRec) || IsNilToken(tkType)))
{
IfFailGo( HENUMInternal::AddElementToEnum(pEnum, TokenFromRid(index, mdtCustomAttribute) ) );
IfFailGo( HENUMInternal::AddElementToEnum(pEnumTmp, TokenFromRid(index, mdtCustomAttribute) ) );
}
}
}
}
}

// set the output parameter
*ppmdEnum = pEnum;
*ppmdEnum = pEnumTmp;
pEnumTmp = 0;
}

// fill the output token buffer
hr = HENUMInternal::EnumWithCount(pEnum, cMax, rCustomAttributes, pcCustomAttributes);
hr = HENUMInternal::EnumWithCount(*ppmdEnum, cMax, rCustomAttributes, pcCustomAttributes);

ErrExit:
HENUMInternal::DestroyEnumIfEmpty(ppmdEnum);
HENUMInternal::DestroyEnum(pEnumTmp);

STOP_MD_PERF(EnumCustomAttributes);
END_ENTRYPOINT_NOTHROW;
Expand Down
Loading