diff options
author | Jeremy Koritzinsky <jekoritz@microsoft.com> | 2021-06-28 19:32:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-28 19:32:11 +0300 |
commit | d0adff8186cbd58f4f63fe2ffdb26077a11390fd (patch) | |
tree | d826287326b8a8ef1f29bcf94d86d746f127ceb4 /src/coreclr/vm | |
parent | 6b5dbf6bdb95aef88262b1eb949f1028c59dc5e2 (diff) |
Fix alloc-dealloc mismatches (#54701)
Diffstat (limited to 'src/coreclr/vm')
-rw-r--r-- | src/coreclr/vm/ilstubresolver.cpp | 3 | ||||
-rw-r--r-- | src/coreclr/vm/methodtable.cpp | 9 | ||||
-rw-r--r-- | src/coreclr/vm/methodtable.h | 44 |
3 files changed, 38 insertions, 18 deletions
diff --git a/src/coreclr/vm/ilstubresolver.cpp b/src/coreclr/vm/ilstubresolver.cpp index 2df8f543e9e..74cd62a7015 100644 --- a/src/coreclr/vm/ilstubresolver.cpp +++ b/src/coreclr/vm/ilstubresolver.cpp @@ -344,8 +344,7 @@ ILStubResolver::AllocGeneratedIL( if (!UseLoaderHeap()) { NewArrayHolder<BYTE> pNewILCodeBuffer = new BYTE[cbCode]; - NewArrayHolder<CompileTimeState> pNewCompileTimeState = (CompileTimeState*)new BYTE[sizeof(CompileTimeState)]; - memset(pNewCompileTimeState, 0, sizeof(CompileTimeState)); + NewHolder<CompileTimeState> pNewCompileTimeState = new CompileTimeState{}; NewArrayHolder<BYTE> pNewLocalSig = NULL; if (0 != cbLocalSig) diff --git a/src/coreclr/vm/methodtable.cpp b/src/coreclr/vm/methodtable.cpp index bb44e829905..a81a0117e6f 100644 --- a/src/coreclr/vm/methodtable.cpp +++ b/src/coreclr/vm/methodtable.cpp @@ -8504,10 +8504,7 @@ MethodTable::GetMethodDataHelper( MethodDataWrapper hDecl(GetMethodData(pMTDecl, FALSE)); MethodDataWrapper hImpl(GetMethodData(pMTImpl, FALSE)); - UINT32 cb = MethodDataInterfaceImpl::GetObjectSize(pMTDecl); - NewArrayHolder<BYTE> pb(new BYTE[cb]); - MethodDataInterfaceImpl * pData = new (pb.GetValue()) MethodDataInterfaceImpl(rgDeclTypeIDs, cDeclTypeIDs, hDecl, hImpl); - pb.SuppressRelease(); + MethodDataInterfaceImpl * pData = new ({ pMTDecl }) MethodDataInterfaceImpl(rgDeclTypeIDs, cDeclTypeIDs, hDecl, hImpl); return pData; } // MethodTable::GetMethodDataHelper @@ -8548,10 +8545,8 @@ MethodTable::MethodData *MethodTable::GetMethodDataHelper(MethodTable *pMTDecl, } else { UINT32 cb = MethodDataObject::GetObjectSize(pMTDecl); - NewArrayHolder<BYTE> pb(new BYTE[cb]); MethodDataHolder h(FindParentMethodDataHelper(pMTDecl)); - pData = new (pb.GetValue()) MethodDataObject(pMTDecl, h.GetValue()); - pb.SuppressRelease(); + pData = new ({ pMTDecl }) MethodDataObject(pMTDecl, h.GetValue()); } } else { diff --git a/src/coreclr/vm/methodtable.h b/src/coreclr/vm/methodtable.h index 3d0ee06b37f..13ff58836fe 100644 --- a/src/coreclr/vm/methodtable.h +++ b/src/coreclr/vm/methodtable.h @@ -3157,7 +3157,7 @@ public: protected: //-------------------------------------------------------------------------------------- - class MethodDataObject : public MethodData + class MethodDataObject final : public MethodData { public: // Static method that returns the amount of memory to allocate for a particular type. @@ -3237,19 +3237,32 @@ protected: { LIMITED_METHOD_CONTRACT; return m_pMDImpl; } }; - // - // At the end of this object is an array, so you cannot derive from this class. - // inline MethodDataObjectEntry *GetEntryData() - { LIMITED_METHOD_CONTRACT; return (MethodDataObjectEntry *)(this + 1); } + { LIMITED_METHOD_CONTRACT; return &m_rgEntries[0]; } inline MethodDataObjectEntry *GetEntry(UINT32 i) { LIMITED_METHOD_CONTRACT; CONSISTENCY_CHECK(i < GetNumMethods()); return GetEntryData() + i; } void FillEntryDataForAncestor(MethodTable *pMT); - // MethodDataObjectEntry m_rgEntries[...]; + // + // At the end of this object is an array + // + MethodDataObjectEntry m_rgEntries[0]; + + public: + struct TargetMethodTable + { + MethodTable* pMT; + }; + + static void* operator new(size_t size, TargetMethodTable targetMT) + { + _ASSERTE(size <= GetObjectSize(targetMT.pMT)); + return ::operator new(GetObjectSize(targetMT.pMT)); + } + static void* operator new(size_t size) = delete; }; // class MethodDataObject //-------------------------------------------------------------------------------------- @@ -3303,7 +3316,7 @@ protected: }; // class MethodDataInterface //-------------------------------------------------------------------------------------- - class MethodDataInterfaceImpl : public MethodData + class MethodDataInterfaceImpl final : public MethodData { public: // Object construction-related methods @@ -3377,12 +3390,25 @@ protected: // inline MethodDataEntry *GetEntryData() - { LIMITED_METHOD_CONTRACT; return (MethodDataEntry *)(this + 1); } + { LIMITED_METHOD_CONTRACT; return &m_rgEntries[0]; } inline MethodDataEntry *GetEntry(UINT32 i) { LIMITED_METHOD_CONTRACT; CONSISTENCY_CHECK(i < GetNumMethods()); return GetEntryData() + i; } - // MethodDataEntry m_rgEntries[...]; + MethodDataEntry m_rgEntries[0]; + + public: + struct TargetMethodTable + { + MethodTable* pMT; + }; + + static void* operator new(size_t size, TargetMethodTable targetMT) + { + _ASSERTE(size <= GetObjectSize(targetMT.pMT)); + return ::operator new(GetObjectSize(targetMT.pMT)); + } + static void* operator new(size_t size) = delete; }; // class MethodDataInterfaceImpl //-------------------------------------------------------------------------------------- |