diff --git a/core/logic/CellArray.h b/core/logic/CellArray.h index 6cea7b91..c77bdc94 100644 --- a/core/logic/CellArray.h +++ b/core/logic/CellArray.h @@ -186,6 +186,12 @@ public: array->m_AllocSize = m_AllocSize; array->m_Size = m_Size; array->m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize); + if (!array->m_Data) + { + delete array; + return NULL; + } + memcpy(array->m_Data, m_Data, sizeof(cell_t) * m_BlockSize * m_Size); return array; } diff --git a/core/logic/smn_adt_array.cpp b/core/logic/smn_adt_array.cpp index 3c0d5b9e..6e6a5c61 100644 --- a/core/logic/smn_adt_array.cpp +++ b/core/logic/smn_adt_array.cpp @@ -503,6 +503,10 @@ static cell_t CloneArray(IPluginContext *pContext, const cell_t *params) } ICellArray *array = oldArray->clone(); + if (!array) + { + return pContext->ThrowNativeError("Failed to clone array. Out of memory."); + } Handle_t hndl = handlesys->CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL); if (!hndl)