From b34179e997ae176faa90c91b720b08b720083500 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 31 Aug 2004 02:05:27 +0000 Subject: [PATCH] Fixed memory leak in detach --- dlls/engine/amxxapi.cpp | 31 ++++--- dlls/engine/entity.cpp | 171 --------------------------------------- dlls/engine/messages.cpp | 1 - 3 files changed, 21 insertions(+), 182 deletions(-) diff --git a/dlls/engine/amxxapi.cpp b/dlls/engine/amxxapi.cpp index 7de6b8f2..a5d2a57e 100755 --- a/dlls/engine/amxxapi.cpp +++ b/dlls/engine/amxxapi.cpp @@ -22,6 +22,27 @@ void EngineError(AMX *amx, char *fmt, ...) MF_RaiseAmxError(amx, AMX_ERR_NATIVE); } +void OnAmxxDetach() +{ + register unsigned int i = 0; + for (i=0; i<256; i++) { + msgHooks[i].clear(); + msgBlocks[i] = 0; + } + for (i=0; ipfnAddToFullPack=NULL; diff --git a/dlls/engine/entity.cpp b/dlls/engine/entity.cpp index a2bf589e..c92080c5 100755 --- a/dlls/engine/entity.cpp +++ b/dlls/engine/entity.cpp @@ -1351,167 +1351,6 @@ static cell AMX_NATIVE_CALL entity_set_size(AMX *amx, cell *params) return 1; } -/*********************** - Offset control natives - ***********************/ - -static cell AMX_NATIVE_CALL get_offset_short(AMX *amx, cell *params) -{ - int idx = params[1]; - int off = params[2]; - - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } - - edict_t *pEnt = INDEXENT2(idx); -#ifdef __linux__ - off += params[3]; -#endif - - return *((short *)pEnt->pvPrivateData + off); -} - -static cell AMX_NATIVE_CALL set_offset_short(AMX *amx, cell *params) -{ - int idx = params[1]; - int off = params[2]; - - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } - - edict_t *pEnt = INDEXENT2(idx); -#ifdef __linux__ - off += params[3]; -#endif - - *((short *)pEnt->pvPrivateData + off) = (short)params[3]; - - return 1; -} - -static cell AMX_NATIVE_CALL get_offset_char(AMX *amx, cell *params) -{ - int idx = params[1]; - int off = params[2]; - - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } - - edict_t *pEnt = INDEXENT2(idx); -#ifdef __linux__ - off += params[3]; -#endif - - char r = *((char *)pEnt->pvPrivateData + off); - return r; -} - -static cell AMX_NATIVE_CALL set_offset_char(AMX *amx, cell *params) -{ - int idx = params[1]; - int off = params[2]; - - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } - - edict_t *pEnt = INDEXENT2(idx); -#ifdef __linux__ - off += params[3]; -#endif - - char data = params[3]; - *((char *)pEnt->pvPrivateData + off) = data; - - return 1; -} - -static cell AMX_NATIVE_CALL get_offset_int(AMX *amx, cell *params) -{ - int idx = params[1]; - int off = params[2]; - - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } - - edict_t *pEnt = INDEXENT2(idx); -#ifdef __linux__ - off += params[3]; -#endif - - return *((int *)pEnt->pvPrivateData + off); -} - -static cell AMX_NATIVE_CALL set_offset_int(AMX *amx, cell *params) -{ - int idx = params[1]; - int off = params[2]; - - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } - - edict_t *pEnt = INDEXENT2(idx); -#ifdef __linux__ - off += params[3]; -#endif - - *((int *)pEnt->pvPrivateData + off) = params[3]; - - return 1; -} - -static cell AMX_NATIVE_CALL get_offset_float(AMX *amx, cell *params) -{ - int idx = params[1]; - int off = params[2]; - - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } - - edict_t *pEnt = INDEXENT2(idx); -#ifdef __linux__ - off += params[3]; -#endif - - REAL fRet = (REAL)(*((REAL*)pEnt->pvPrivateData + off)); - - return amx_ftoc(fRet); -} - -static cell AMX_NATIVE_CALL set_offset_float(AMX *amx, cell *params) -{ - int idx = params[1]; - int off = params[2]; - - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } - - edict_t *pEnt = INDEXENT2(idx); -#ifdef __linux__ - off += params[3]; -#endif - - REAL fVal = amx_ctof(params[3]); - *((float *)pEnt->pvPrivateData + off) = fVal; - - return 1; -} - static cell AMX_NATIVE_CALL get_entity_pointer(AMX *amx, cell *params) // get_entity_pointer(index, pointer[], len); = 3 params { return 0; @@ -1780,16 +1619,6 @@ AMX_NATIVE_INFO ent_Natives[] = { {"fake_touch", fake_touch}, {"force_use", force_use}, - {"get_offset_short", get_offset_short}, - {"set_offset_short", set_offset_short}, - {"get_offset_char", get_offset_char}, - {"set_offset_char", set_offset_char}, - {"get_offset", get_offset_int}, - {"set_offset", set_offset_int}, - {"get_offset_int", get_offset_int}, - {"set_offset_int", set_offset_int}, - {"get_offset_float", get_offset_float}, - {"set_offset_float", set_offset_float}, {"get_entity_pointer", get_entity_pointer}, {"find_ent_in_sphere", find_ent_in_sphere}, diff --git a/dlls/engine/messages.cpp b/dlls/engine/messages.cpp index a0b9f196..9c22ea03 100755 --- a/dlls/engine/messages.cpp +++ b/dlls/engine/messages.cpp @@ -308,7 +308,6 @@ static cell AMX_NATIVE_CALL register_message(AMX *amx, cell *params) int len; if (params[1]>0 && params[1] < 256) { int id = MF_RegisterSPForwardByName(amx, MF_GetAmxString(amx, params[2], 0, &len), FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE); -// MF_Log("Registering message %d with result %d", params[1], id); if (id != -1) { msgHooks[params[1]].push_back(id);