Fixed memory leaks

Optimized message handling a bit
This commit is contained in:
David Anderson 2005-07-14 04:50:46 +00:00
parent 116984afed
commit db293cc451
4 changed files with 60 additions and 67 deletions

View File

@ -18,14 +18,14 @@ void ClearHooks()
msgHooks[i].clear();
msgBlocks[i] = 0;
}
for (i=0; i<Msg.size(); i++)
delete Msg[i];
for (i=0; i<Touches.size(); i++)
delete Touches[i];
for (i=0; i<Impulses.size(); i++)
delete Impulses[i];
for (i=0; i<Thinks.size(); i++)
delete Thinks[i];
Msg.clear();
Touches.clear();
Impulses.clear();

View File

@ -151,12 +151,10 @@ static cell AMX_NATIVE_CALL DispatchKeyValue(AMX *amx, cell *params)
int iLength;
char *char1 = MF_GetAmxString(amx, params[1], 0, &iLength);
char *char2 = MF_GetAmxString(amx, params[2], 1, &iLength);
char *charA = new char[strlen(char1)+1];
char *charB = new char[strlen(char2)+1];
strcpy(charA, char1);
strcpy(charB, char2);
g_pkvd->szKeyName = charA;
g_pkvd->szValue = charB;
const char *charA = STRING(ALLOC_STRING(char1));
const char *charB = STRING(ALLOC_STRING(char2));
g_pkvd->szKeyName = const_cast<char *>(charA);
g_pkvd->szValue = const_cast<char *>(charB);
}
return 1;
}
@ -1259,10 +1257,7 @@ static cell AMX_NATIVE_CALL entity_set_model(AMX *amx, cell *params)
edict_t *pEnt = INDEXENT2(iEnt);
int iLen;
char *szModel = MF_GetAmxString(amx, params[2], 0, &iLen);
char *szStatic = new char[iLen+1];
memset(szStatic, 0, iLen+1);
strcpy(szStatic, szModel);
const char *szStatic = STRING(ALLOC_STRING(szModel));
SET_MODEL(pEnt, szStatic);
@ -1495,7 +1490,7 @@ static cell AMX_NATIVE_CALL find_ent_by_owner(AMX *amx, cell *params) // native
static cell AMX_NATIVE_CALL get_grenade_id(AMX *amx, cell *params) /* 4 param */
{
int index = params[1];
char* szModel;
const char *szModel;
CHECK_ENTITY(index);
@ -1506,10 +1501,8 @@ static cell AMX_NATIVE_CALL get_grenade_id(AMX *amx, cell *params) /* 4 param *
while (!FNullEnt(pentFind)) {
if (pentFind->v.owner == pentOwner) {
if (params[3]>0) {
szModel = new char[params[3]];
szModel = (char*)STRING(pentFind->v.model);
MF_SetAmxString(amx, params[2], szModel, params[3]);
delete [] szModel;
return ENTINDEX(pentFind);
}
}

View File

@ -1,6 +1,6 @@
#include "engine.h"
CVector<argMsg*> Msg;
CVector<argMsg> Msg;
CVector<int> msgHooks[256];
int msgBlocks[256] = {0};
int msgDest;
@ -114,13 +114,13 @@ void WriteByte(int iValue)
RETURN_META(MRES_SUPERCEDE);
} else if (inhook) {
if (++msgCount > Msg.size()) {
argMsg *p = new argMsg();
p->iData = iValue;
p->type = arg_byte;
argMsg p;
p.iData = iValue;
p.type = arg_byte;
Msg.push_back(p);
} else {
Msg[msgCount-1]->iData = iValue;
Msg[msgCount-1]->type = arg_byte;
Msg[msgCount-1].iData = iValue;
Msg[msgCount-1].type = arg_byte;
}
RETURN_META(MRES_SUPERCEDE);
}
@ -134,13 +134,13 @@ void WriteChar(int iValue)
RETURN_META(MRES_SUPERCEDE);
} else if (inhook) {
if (++msgCount > Msg.size()) {
argMsg *p = new argMsg();
p->iData = iValue;
p->type = arg_char;
argMsg p;
p.iData = iValue;
p.type = arg_char;
Msg.push_back(p);
} else {
Msg[msgCount-1]->iData = iValue;
Msg[msgCount-1]->type = arg_char;
Msg[msgCount-1].iData = iValue;
Msg[msgCount-1].type = arg_char;
}
RETURN_META(MRES_SUPERCEDE);
}
@ -154,13 +154,13 @@ void WriteShort(int iValue)
RETURN_META(MRES_SUPERCEDE);
} else if (inhook) {
if (++msgCount > Msg.size()) {
argMsg *p = new argMsg();
p->iData = iValue;
p->type = arg_short;
argMsg p;
p.iData = iValue;
p.type = arg_short;
Msg.push_back(p);
} else {
Msg[msgCount-1]->iData = iValue;
Msg[msgCount-1]->type = arg_short;
Msg[msgCount-1].iData = iValue;
Msg[msgCount-1].type = arg_short;
}
RETURN_META(MRES_SUPERCEDE);
}
@ -174,13 +174,13 @@ void WriteLong(int iValue)
RETURN_META(MRES_SUPERCEDE);
} else if (inhook) {
if (++msgCount > Msg.size()) {
argMsg *p = new argMsg();
p->iData = iValue;
p->type = arg_long;
argMsg p;
p.iData = iValue;
p.type = arg_long;
Msg.push_back(p);
} else {
Msg[msgCount-1]->iData = iValue;
Msg[msgCount-1]->type = arg_long;
Msg[msgCount-1].iData = iValue;
Msg[msgCount-1].type = arg_long;
}
RETURN_META(MRES_SUPERCEDE);
}
@ -194,13 +194,13 @@ void WriteAngle(float flValue)
RETURN_META(MRES_SUPERCEDE);
} else if (inhook) {
if (++msgCount > Msg.size()) {
argMsg *p = new argMsg();
p->fData = flValue;
p->type = arg_angle;
argMsg p;
p.fData = flValue;
p.type = arg_angle;
Msg.push_back(p);
} else {
Msg[msgCount-1]->fData = flValue;
Msg[msgCount-1]->type = arg_angle;
Msg[msgCount-1].fData = flValue;
Msg[msgCount-1].type = arg_angle;
}
RETURN_META(MRES_SUPERCEDE);
}
@ -214,13 +214,13 @@ void WriteCoord(float flValue)
RETURN_META(MRES_SUPERCEDE);
} else if (inhook) {
if (++msgCount > Msg.size()) {
argMsg *p = new argMsg();
p->fData = flValue;
p->type = arg_coord;
argMsg p;
p.fData = flValue;
p.type = arg_coord;
Msg.push_back(p);
} else {
Msg[msgCount-1]->fData = flValue;
Msg[msgCount-1]->type = arg_coord;
Msg[msgCount-1].fData = flValue;
Msg[msgCount-1].type = arg_coord;
}
RETURN_META(MRES_SUPERCEDE);
}
@ -234,13 +234,13 @@ void WriteString(const char *sz)
RETURN_META(MRES_SUPERCEDE);
} else if (inhook) {
if (++msgCount > Msg.size()) {
argMsg *p = new argMsg();
p->cData.assign(sz);
p->type = arg_string;
argMsg p;
p.cData.assign(sz);
p.type = arg_string;
Msg.push_back(p);
} else {
Msg[msgCount-1]->cData.assign(sz);
Msg[msgCount-1]->type = arg_string;
Msg[msgCount-1].cData.assign(sz);
Msg[msgCount-1].type = arg_string;
}
RETURN_META(MRES_SUPERCEDE);
}
@ -254,13 +254,13 @@ void WriteEntity(int iValue)
RETURN_META(MRES_SUPERCEDE);
} else if (inhook) {
if (++msgCount > Msg.size()) {
argMsg *p = new argMsg();
p->iData = iValue;
p->type = arg_entity;
argMsg p;
p.iData = iValue;
p.type = arg_entity;
Msg.push_back(p);
} else {
Msg[msgCount-1]->iData = iValue;
Msg[msgCount-1]->type = arg_entity;
Msg[msgCount-1].iData = iValue;
Msg[msgCount-1].type = arg_entity;
}
RETURN_META(MRES_SUPERCEDE);
}
@ -292,8 +292,8 @@ void MessageEnd(void)
}
MESSAGE_BEGIN(msgDest, msgType, msgOrigin, msgpEntity);
for (i=0; i<msgCount; i++) {
Msg[i]->Send();
Msg[i]->Reset();
Msg[i].Send();
Msg[i].Reset();
}
MESSAGE_END();
msgCount = 0;
@ -361,7 +361,7 @@ static cell AMX_NATIVE_CALL get_msg_argtype(AMX *amx, cell *params)
return 0;
}
return Msg[argn]->type;
return Msg[argn].type;
}
static cell AMX_NATIVE_CALL get_msg_arg_int(AMX *amx, cell *params)
@ -373,7 +373,7 @@ static cell AMX_NATIVE_CALL get_msg_arg_int(AMX *amx, cell *params)
return 0;
}
int iVal = Msg[argn]->iData;
int iVal = Msg[argn].iData;
return iVal;
}
@ -387,8 +387,8 @@ static cell AMX_NATIVE_CALL set_msg_arg_int(AMX *amx, cell *params)
return 0;
}
Msg[argn]->type = params[2];
Msg[argn]->iData = params[3];
Msg[argn].type = params[2];
Msg[argn].iData = params[3];
return 1;
}
@ -402,7 +402,7 @@ static cell AMX_NATIVE_CALL get_msg_arg_float(AMX *amx, cell *params)
return 0;
}
return amx_ftoc(Msg[argn]->fData);
return amx_ftoc(Msg[argn].fData);
}
static cell AMX_NATIVE_CALL set_msg_arg_float(AMX *amx, cell *params)
@ -416,7 +416,7 @@ static cell AMX_NATIVE_CALL set_msg_arg_float(AMX *amx, cell *params)
REAL fVal = amx_ctof(params[2]);
Msg[argn]->fData = fVal;
Msg[argn].fData = fVal;
return 1;
}
@ -430,7 +430,7 @@ static cell AMX_NATIVE_CALL get_msg_arg_string(AMX *amx, cell *params)
return 0;
}
const char *szVal = Msg[argn]->cData.c_str();
const char *szVal = Msg[argn].cData.c_str();
return MF_SetAmxString(amx, params[2], szVal?szVal:"", params[3]);
}
@ -447,7 +447,7 @@ static cell AMX_NATIVE_CALL set_msg_arg_string(AMX *amx, cell *params)
char *szVal = MF_GetAmxString(amx, params[2], 0, &iLen);
Msg[argn]->cData.assign(szVal);
Msg[argn].cData.assign(szVal);
return 1;
}

View File

@ -41,7 +41,7 @@ public:
};
extern AMX_NATIVE_INFO msg_Natives[];
extern CVector<argMsg*> Msg;
extern CVector<argMsg> Msg;
extern CVector<int> msgHooks[256];
extern int msgBlocks[256];