From 642eb769b2f6276fa142bb07d64428fd26d48d89 Mon Sep 17 00:00:00 2001 From: Pavol Marko Date: Fri, 28 May 2004 11:24:59 +0000 Subject: [PATCH] Added a check for memory allocation failure --- amxmodx/CEvent.cpp | 4 ++++ amxmodx/CForward.cpp | 7 ++++++- amxmodx/CMenu.cpp | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/amxmodx/CEvent.cpp b/amxmodx/CEvent.cpp index 1de8f76e..bd6b4a72 100755 --- a/amxmodx/CEvent.cpp +++ b/amxmodx/CEvent.cpp @@ -86,6 +86,10 @@ void EventsMngr::NextParam() { // copy to tmp tmp = new MsgDataEntry[m_ParseVaultSize]; + if (!tmp) + { + return; // :TODO: Error report !! + } memcpy(tmp, m_ParseVault, m_ParseVaultSize * sizeof(MsgDataEntry)); tmpSize = m_ParseVaultSize; delete [] m_ParseVault; diff --git a/amxmodx/CForward.cpp b/amxmodx/CForward.cpp index aeaf578b..9366bf3d 100755 --- a/amxmodx/CForward.cpp +++ b/amxmodx/CForward.cpp @@ -46,6 +46,8 @@ CForward::CForward(const char *name, ForwardExecType et, int numParams, const Fo if (amx_FindPublic((*iter).getAMX(), name, &func) == AMX_ERR_NONE) { tmp = new AMXForward; + if (!tmp) + return; // :TODO: Better error report!!! tmp->pPlugin = &(*iter); tmp->func = func; m_Funcs.put(tmp); @@ -267,7 +269,10 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays) int CForwardMngr::registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam * paramTypes) { int retVal = m_Forwards.size() << 1; - m_Forwards.push_back(new CForward(funcName, et, numParams, paramTypes)); + CForward *tmp = new CForward(funcName, et, numParams, paramTypes); + if (!tmp) + return -1; // should be invalid + m_Forwards.push_back(tmp); return retVal; } diff --git a/amxmodx/CMenu.cpp b/amxmodx/CMenu.cpp index 1650f45c..0efc371d 100755 --- a/amxmodx/CMenu.cpp +++ b/amxmodx/CMenu.cpp @@ -62,6 +62,8 @@ int MenuMngr::registerMenuId(const char* n, AMX* a ) int id = findMenuId( n, a ); if (id) return id; headid = new MenuIdEle( n, a , headid ); + if (headid) + return 0; // :TODO: Better error report return headid->id; }