From 08318afbeb726eb80f212c70310e5750daec5abf Mon Sep 17 00:00:00 2001 From: Omair Majid Date: Tue, 16 Apr 2019 01:14:48 -0400 Subject: [PATCH] Use NewArrayHolder for array types in src/debug (#24013) 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 isntead to fix this. --- src/debug/daccess/dacdbiimpl.cpp | 6 +++--- src/debug/di/process.cpp | 2 +- src/debug/di/rstype.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/debug/daccess/dacdbiimpl.cpp b/src/debug/daccess/dacdbiimpl.cpp index 2941714..4f878cc 100644 --- a/src/debug/daccess/dacdbiimpl.cpp +++ b/src/debug/daccess/dacdbiimpl.cpp @@ -2238,7 +2238,7 @@ TypeHandle DacDbiInterfaceImpl::TypeDataWalk::FnPtrTypeArg(DebuggerIPCE_TypeArgD { // allocate space to store a list of type handles, one for the return type and one for each // of the parameter types of the function to which the FnPtr type refers. - NewHolder pInst(new TypeHandle[sizeof(TypeHandle) * pFnPtrTypeInfo->numTypeArgs]); + NewArrayHolder pInst(new TypeHandle[sizeof(TypeHandle) * pFnPtrTypeInfo->numTypeArgs]); if (ReadLoadedTypeHandles(retrieveWhich, pFnPtrTypeInfo->numTypeArgs, pInst)) { @@ -3058,7 +3058,7 @@ TypeHandle DacDbiInterfaceImpl::GetExactClassTypeHandle(DebuggerIPCE_ExpandedTyp ThrowHR(E_OUTOFMEMORY); } - NewHolder pInst(new TypeHandle[allocSize.Value()]); + NewArrayHolder pInst(new TypeHandle[allocSize.Value()]); // convert the type information for each parameter to its corresponding type handle // and store it in the list @@ -3093,7 +3093,7 @@ TypeHandle DacDbiInterfaceImpl::GetExactFnPtrTypeHandle(ArgInfoList * pArgInfo) { ThrowHR(E_OUTOFMEMORY); } - NewHolder pInst(new TypeHandle[allocSize.Value()]); + NewArrayHolder pInst(new TypeHandle[allocSize.Value()]); // convert the type information for each parameter to its corresponding type handle // and store it in the list diff --git a/src/debug/di/process.cpp b/src/debug/di/process.cpp index 1536f8c..58c06a0 100644 --- a/src/debug/di/process.cpp +++ b/src/debug/di/process.cpp @@ -9578,7 +9578,7 @@ void Ls_Rs_BaseBuffer::CopyLSDataToRSWorker(ICorDebugDataTarget * pTarget) ThrowHR(E_INVALIDARG); } - NewHolder pData(new BYTE[cbCacheSize]); + NewArrayHolder pData(new BYTE[cbCacheSize]); ULONG32 cbRead; HRESULT hrRead = pTarget->ReadVirtual(PTR_TO_CORDB_ADDRESS(m_pbLS), pData, cbCacheSize , &cbRead); diff --git a/src/debug/di/rstype.cpp b/src/debug/di/rstype.cpp index a85ab0d..8b7c294 100644 --- a/src/debug/di/rstype.cpp +++ b/src/debug/di/rstype.cpp @@ -1549,7 +1549,7 @@ HRESULT CordbType::InitInstantiationTypeHandle(BOOL fForceInit) { ThrowHR(E_INVALIDARG); } - NewHolder pArgTypeData(new DebuggerIPCE_BasicTypeData[bufferSize.Value()]); + NewArrayHolder pArgTypeData(new DebuggerIPCE_BasicTypeData[bufferSize.Value()]); // We will have already called Init on each of the type parameters further above. Now we build a // list of type information for each type parameter. -- 2.7.4