From b6febae2fa2234f8903abfd7f810128f32d1c312 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Tue, 24 Mar 2015 01:25:36 +0100 Subject: [PATCH] Fix crash under linux in Hamsandwich module Fix crash under linux in Hamsandwich module --- modules/hamsandwich/forward.h | 4 +++- modules/hamsandwich/hook.h | 4 ++-- modules/hamsandwich/hook_native.cpp | 6 ++++-- modules/hamsandwich/hook_specialbot.cpp | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/hamsandwich/forward.h b/modules/hamsandwich/forward.h index f6296497..6f95b14e 100644 --- a/modules/hamsandwich/forward.h +++ b/modules/hamsandwich/forward.h @@ -16,6 +16,8 @@ #ifndef FORWARD_H #define FORWARD_H +#include + enum fwdstate { FSTATE_INVALID = 0, @@ -25,7 +27,7 @@ enum fwdstate FSTATE_DESTROY }; -class Forward +class Forward :public ke::Refcounted { public: int id; // id of the forward diff --git a/modules/hamsandwich/hook.h b/modules/hamsandwich/hook.h index 63d64572..1db43642 100644 --- a/modules/hamsandwich/hook.h +++ b/modules/hamsandwich/hook.h @@ -89,12 +89,12 @@ public: for (size_t i = 0; i < pre.length(); ++i) { - delete pre.at(i); + pre.at(i)->Release(); } for (size_t i = 0; i < post.length(); ++i) { - delete post.at(i); + post.at(i)->Release(); } pre.clear(); diff --git a/modules/hamsandwich/hook_native.cpp b/modules/hamsandwich/hook_native.cpp index 80ad2986..27416828 100644 --- a/modules/hamsandwich/hook_native.cpp +++ b/modules/hamsandwich/hook_native.cpp @@ -583,6 +583,7 @@ static cell AMX_NATIVE_CALL RegisterHam(AMX *amx, cell *params) } Forward *pfwd = new Forward(fwd); + pfwd->AddRef(); // We've passed all tests... if (strcmp(classname, "player") == 0 && enableSpecialBot) @@ -676,6 +677,9 @@ static cell AMX_NATIVE_CALL RegisterHamFromEntity(AMX *amx, cell *params) // We've passed all tests... + Forward *pfwd = new Forward(fwd); + pfwd->AddRef(); + int **ivtable=(int **)vtable; void *vfunction=(void *)ivtable[hooklist[func].vtid]; @@ -687,7 +691,6 @@ static cell AMX_NATIVE_CALL RegisterHamFromEntity(AMX *amx, cell *params) if (hooks[func].at(i)->tramp == vfunction) { // Yes, this function is hooked - Forward *pfwd=new Forward(fwd); if (post) { hooks[func].at(i)->post.append(pfwd); @@ -710,7 +713,6 @@ static cell AMX_NATIVE_CALL RegisterHamFromEntity(AMX *amx, cell *params) Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname); hooks[func].append(hook); - Forward *pfwd=new Forward(fwd); if (post) { hook->post.append(pfwd); diff --git a/modules/hamsandwich/hook_specialbot.cpp b/modules/hamsandwich/hook_specialbot.cpp index 2e3e99ed..9f9469e3 100644 --- a/modules/hamsandwich/hook_specialbot.cpp +++ b/modules/hamsandwich/hook_specialbot.cpp @@ -84,6 +84,8 @@ void CHamSpecialBotHandler::RegisterHamSpecialBot(AMX *amx, int &func, const cha void CHamSpecialBotHandler::RegisterChecked(AMX *amx, int &func, const char *function, int &post, Forward *pfwd) { + pfwd->AddRef(); + void **vtable = m_specialbot_vtable; int **ivtable=(int **)vtable;