Skip to content

Commit 18f9a07

Browse files
authored
Free temporary enums on failure (#50471)
* Free temporary enums on failure * PR feedback
1 parent af5eae3 commit 18f9a07

File tree

4 files changed

+107
-85
lines changed

4 files changed

+107
-85
lines changed

src/coreclr/md/compiler/assemblymd.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ STDMETHODIMP RegMeta::EnumExportedTypes( // S_OK or error
444444
BEGIN_ENTRYPOINT_NOTHROW;
445445

446446
HENUMInternal **ppmdEnum = reinterpret_cast<HENUMInternal **> (phEnum);
447-
HENUMInternal *pEnum;
447+
HENUMInternal *pEnum = NULL;
448448

449449
LOG((LOGMD, "MD RegMeta::EnumExportedTypes(%#08x, %#08x, %#08x, %#08x)\n",
450450
phEnum, rExportedTypes, cMax, pcTokens));
@@ -488,14 +488,14 @@ STDMETHODIMP RegMeta::EnumExportedTypes( // S_OK or error
488488

489489
// set the output parameter.
490490
*ppmdEnum = pEnum;
491+
pEnum = NULL;
491492
}
492-
else
493-
pEnum = *ppmdEnum;
494493

495494
// we can only fill the minimum of what the caller asked for or what we have left.
496-
IfFailGo(HENUMInternal::EnumWithCount(pEnum, cMax, rExportedTypes, pcTokens));
495+
IfFailGo(HENUMInternal::EnumWithCount(*ppmdEnum, cMax, rExportedTypes, pcTokens));
497496
ErrExit:
498497
HENUMInternal::DestroyEnumIfEmpty(ppmdEnum);
498+
HENUMInternal::DestroyEnum(pEnum);
499499

500500
STOP_MD_PERF(EnumExportedTypes);
501501
END_ENTRYPOINT_NOTHROW;

src/coreclr/md/compiler/custattr_import.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
108108
HENUMInternal **ppmdEnum = reinterpret_cast<HENUMInternal **> (phEnum);
109109
RID ridStart;
110110
RID ridEnd;
111-
HENUMInternal *pEnum = *ppmdEnum;
111+
HENUMInternal *pEnum = NULL;
112112
CustomAttributeRec *pRec;
113113
ULONG index;
114114

@@ -117,7 +117,7 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
117117
START_MD_PERF();
118118
LOCKREAD();
119119

120-
if ( pEnum == 0 )
120+
if ( *ppmdEnum == 0 )
121121
{
122122
// instantiating a new ENUM
123123
CMiniMdRW *pMiniMd = &(m_pStgdb->m_MiniMd);
@@ -220,13 +220,15 @@ STDMETHODIMP RegMeta::EnumCustomAttributes(
220220

221221
// set the output parameter
222222
*ppmdEnum = pEnum;
223+
pEnum = NULL;
223224
}
224225

225226
// fill the output token buffer
226-
hr = HENUMInternal::EnumWithCount(pEnum, cMax, rCustomAttributes, pcCustomAttributes);
227+
hr = HENUMInternal::EnumWithCount(*ppmdEnum, cMax, rCustomAttributes, pcCustomAttributes);
227228

228229
ErrExit:
229230
HENUMInternal::DestroyEnumIfEmpty(ppmdEnum);
231+
HENUMInternal::DestroyEnum(pEnum);
230232

231233
STOP_MD_PERF(EnumCustomAttributes);
232234
END_ENTRYPOINT_NOTHROW;

0 commit comments

Comments
 (0)