Fix crash in CloneArray for too large arrays (#566)
If there is not enough memory to clone an array, throw an error instead of crashing the server.
This commit is contained in:
parent
d3d16a93cf
commit
b74573fa12
@ -186,6 +186,12 @@ public:
|
|||||||
array->m_AllocSize = m_AllocSize;
|
array->m_AllocSize = m_AllocSize;
|
||||||
array->m_Size = m_Size;
|
array->m_Size = m_Size;
|
||||||
array->m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize);
|
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);
|
memcpy(array->m_Data, m_Data, sizeof(cell_t) * m_BlockSize * m_Size);
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@ -503,6 +503,10 @@ static cell_t CloneArray(IPluginContext *pContext, const cell_t *params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ICellArray *array = oldArray->clone();
|
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);
|
Handle_t hndl = handlesys->CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL);
|
||||||
if (!hndl)
|
if (!hndl)
|
||||||
|
Loading…
Reference in New Issue
Block a user