diff options
author | Omair Majid <omajid@redhat.com> | 2019-04-16 01:12:39 -0400 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2019-04-15 22:12:39 -0700 |
commit | 0f838a7c22c6e19748582ced5e03a8e273f63062 (patch) | |
tree | ae2096443906a638c83c9753cf2577383f52fc8b /src | |
parent | f6938e2b5497cce88ab7b3643ab5f3174d8bb3e7 (diff) | |
download | coreclr-0f838a7c22c6e19748582ced5e03a8e273f63062.tar.gz coreclr-0f838a7c22c6e19748582ced5e03a8e273f63062.tar.bz2 coreclr-0f838a7c22c6e19748582ced5e03a8e273f63062.zip |
Use NewArrayHolder for array types (#24017)
This touches all the code outside of src/debug/.
Using a NewHolder with array types means that when the holder is ready
to release the memory, it ends up invoking `delete` (instead of
`delete[]`) on that array. This is an undefined behaviour.
Use NewArrayHolder instead to fix this.
Diffstat (limited to 'src')
-rw-r--r-- | src/md/runtime/mdinternalro.cpp | 2 | ||||
-rw-r--r-- | src/vm/dynamicmethod.cpp | 8 | ||||
-rw-r--r-- | src/vm/ilstubresolver.cpp | 8 | ||||
-rw-r--r-- | src/vm/methodtable.cpp | 6 | ||||
-rw-r--r-- | src/vm/runtimehandles.cpp | 2 | ||||
-rw-r--r-- | src/vm/threadstatics.cpp | 2 |
6 files changed, 14 insertions, 14 deletions
diff --git a/src/md/runtime/mdinternalro.cpp b/src/md/runtime/mdinternalro.cpp index d16d2b02eb..a4f59a37b2 100644 --- a/src/md/runtime/mdinternalro.cpp +++ b/src/md/runtime/mdinternalro.cpp @@ -2172,7 +2172,7 @@ HRESULT MDInternalRO::GetPropertyInfoForMethodDef( // Result. // Lazy initialization of m_pMethodSemanticsMap if ((ridMax > 10) && (m_pMethodSemanticsMap == NULL)) { - NewHolder<CMethodSemanticsMap> pMethodSemanticsMap = new (nothrow) CMethodSemanticsMap[ridMax]; + NewArrayHolder<CMethodSemanticsMap> pMethodSemanticsMap = new (nothrow) CMethodSemanticsMap[ridMax]; if (pMethodSemanticsMap != NULL) { // Fill the table in MethodSemantics order. diff --git a/src/vm/dynamicmethod.cpp b/src/vm/dynamicmethod.cpp index 5b9a6fac03..611a9852d6 100644 --- a/src/vm/dynamicmethod.cpp +++ b/src/vm/dynamicmethod.cpp @@ -1109,7 +1109,7 @@ BYTE* LCGMethodResolver::GetCodeInfo(unsigned *pCodeSize, unsigned *pStackSize, }; U1ARRAYREF dataArray = (U1ARRAYREF) getCodeInfo.Call_RetOBJECTREF(args); DWORD codeSize = dataArray->GetNumComponents(); - NewHolder<BYTE> code(new BYTE[codeSize]); + NewArrayHolder<BYTE> code(new BYTE[codeSize]); memcpy(code, dataArray->GetDataPtr(), codeSize); m_CodeSize = codeSize; _ASSERTE(FitsIn<unsigned short>(stackSize)); @@ -1157,7 +1157,7 @@ LCGMethodResolver::GetLocalSig() }; U1ARRAYREF dataArray = (U1ARRAYREF) getLocalsSignature.Call_RetOBJECTREF(args); DWORD localSigSize = dataArray->GetNumComponents(); - NewHolder<COR_SIGNATURE> localSig(new COR_SIGNATURE[localSigSize]); + NewArrayHolder<COR_SIGNATURE> localSig(new COR_SIGNATURE[localSigSize]); memcpy((void *)localSig, dataArray->GetDataPtr(), localSigSize); m_LocalSig = SigPointer((PCCOR_SIGNATURE)localSig, localSigSize); @@ -1504,7 +1504,7 @@ void* ChunkAllocator::New(size_t size) if (size + (sizeof(void*) * 2) < CHUNK_SIZE) { // make the allocation - NewHolder<BYTE> newBlock(new BYTE[CHUNK_SIZE]); + NewArrayHolder<BYTE> newBlock(new BYTE[CHUNK_SIZE]); pNewBlock = (BYTE*)newBlock; ((size_t*)pNewBlock)[1] = CHUNK_SIZE - size - (sizeof(void*) * 2); LOG((LF_BCL, LL_INFO10, "Level1 - DM - Allocator [0x%p] - new block {0x%p}\n", this, pNewBlock)); @@ -1513,7 +1513,7 @@ void* ChunkAllocator::New(size_t size) else { // request bigger than default size this is going to be a single block - NewHolder<BYTE> newBlock(new BYTE[size + (sizeof(void*) * 2)]); + NewArrayHolder<BYTE> newBlock(new BYTE[size + (sizeof(void*) * 2)]); pNewBlock = (BYTE*)newBlock; ((size_t*)pNewBlock)[1] = 0; // no available bytes left LOG((LF_BCL, LL_INFO10, "Level1 - DM - Allocator [0x%p] - new BIG block {0x%p}\n", this, pNewBlock)); diff --git a/src/vm/ilstubresolver.cpp b/src/vm/ilstubresolver.cpp index 5b2f8a462e..4d429626eb 100644 --- a/src/vm/ilstubresolver.cpp +++ b/src/vm/ilstubresolver.cpp @@ -266,7 +266,7 @@ ILStubResolver::SetStubTargetMethodSig( } CONTRACTL_END; - NewHolder<BYTE> pNewSig = new BYTE[cbStubTargetSigLength]; + NewArrayHolder<BYTE> pNewSig = new BYTE[cbStubTargetSigLength]; memcpyNoGCRefs((void *)pNewSig, pStubTargetMethodSig, cbStubTargetSigLength); @@ -313,9 +313,9 @@ ILStubResolver::AllocGeneratedIL( #if !defined(DACCESS_COMPILE) _ASSERTE(0 != cbCode); - NewHolder<BYTE> pNewILCodeBuffer = NULL; - NewHolder<BYTE> pNewLocalSig = NULL; - NewHolder<CompileTimeState> pNewCompileTimeState = NULL; + NewArrayHolder<BYTE> pNewILCodeBuffer = NULL; + NewArrayHolder<BYTE> pNewLocalSig = NULL; + NewArrayHolder<CompileTimeState> pNewCompileTimeState = NULL; pNewCompileTimeState = (CompileTimeState *)new BYTE[sizeof(CompileTimeState)]; memset(pNewCompileTimeState, 0, sizeof(CompileTimeState)); diff --git a/src/vm/methodtable.cpp b/src/vm/methodtable.cpp index 34381fa2aa..43ba55b4e5 100644 --- a/src/vm/methodtable.cpp +++ b/src/vm/methodtable.cpp @@ -8976,7 +8976,7 @@ void MethodTable::CheckInitMethodDataCache() if (s_pMethodDataCache == NULL) { UINT32 cb = MethodDataCache::GetObjectSize(8); - NewHolder<BYTE> hb(new BYTE[cb]); + NewArrayHolder<BYTE> hb(new BYTE[cb]); MethodDataCache *pCache = new (hb.GetValue()) MethodDataCache(8); if (InterlockedCompareExchangeT( &s_pMethodDataCache, pCache, NULL) == NULL) @@ -9085,7 +9085,7 @@ MethodTable::GetMethodDataHelper( MethodDataWrapper hImpl(GetMethodData(pMTImpl, FALSE)); UINT32 cb = MethodDataInterfaceImpl::GetObjectSize(pMTDecl); - NewHolder<BYTE> pb(new BYTE[cb]); + NewArrayHolder<BYTE> pb(new BYTE[cb]); MethodDataInterfaceImpl * pData = new (pb.GetValue()) MethodDataInterfaceImpl(rgDeclTypeIDs, cDeclTypeIDs, hDecl, hImpl); pb.SuppressRelease(); @@ -9128,7 +9128,7 @@ MethodTable::MethodData *MethodTable::GetMethodDataHelper(MethodTable *pMTDecl, } else { UINT32 cb = MethodDataObject::GetObjectSize(pMTDecl); - NewHolder<BYTE> pb(new BYTE[cb]); + NewArrayHolder<BYTE> pb(new BYTE[cb]); MethodDataHolder h(FindParentMethodDataHelper(pMTDecl)); pData = new (pb.GetValue()) MethodDataObject(pMTDecl, h.GetValue()); pb.SuppressRelease(); diff --git a/src/vm/runtimehandles.cpp b/src/vm/runtimehandles.cpp index d0a2b043d9..620886e814 100644 --- a/src/vm/runtimehandles.cpp +++ b/src/vm/runtimehandles.cpp @@ -3033,7 +3033,7 @@ FCIMPL5(ReflectMethodObject*, ModuleHandle::GetDynamicMethod, ReflectMethodObjec U1ARRAYREF dataArray = (U1ARRAYREF)sig; DWORD sigSize = dataArray->GetNumComponents(); - NewHolder<BYTE> pSig(new BYTE[sigSize]); + NewArrayHolder<BYTE> pSig(new BYTE[sigSize]); memcpy(pSig, dataArray->GetDataPtr(), sigSize); DWORD length = gc.nameRef->GetStringLength(); diff --git a/src/vm/threadstatics.cpp b/src/vm/threadstatics.cpp index 562ac8bf53..999c1210f1 100644 --- a/src/vm/threadstatics.cpp +++ b/src/vm/threadstatics.cpp @@ -647,7 +647,7 @@ PTR_ThreadLocalModule ThreadStatics::AllocateAndInitTLM(ModuleIndex index, PTR_T _ASSERTE(pThreadLocalBlock != NULL); _ASSERTE(pModule != NULL); - NewHolder<ThreadLocalModule> pThreadLocalModule = AllocateTLM(pModule); + NewArrayHolder<ThreadLocalModule> pThreadLocalModule = AllocateTLM(pModule); pThreadLocalBlock->AllocateThreadStaticHandles(pModule, pThreadLocalModule); |