Redid lots of destruction stuff.

This commit is contained in:
David Anderson 2004-03-15 20:27:53 +00:00
parent 439550c2ac
commit ee947b1673
2 changed files with 44 additions and 31 deletions

View File

@ -34,10 +34,6 @@
#define VERSION "0.15" #define VERSION "0.15"
#include <string>
using namespace std;
plugin_info_t Plugin_info = { plugin_info_t Plugin_info = {
META_INTERFACE_VERSION, // ifvers META_INTERFACE_VERSION, // ifvers
@ -378,6 +374,7 @@ public:
writeangle = 0.0; writeangle = 0.0;
writecoord = 0.0; writecoord = 0.0;
writeentity = 0; writeentity = 0;
writestring = NULL;
} }
argStack* arg() argStack* arg()
@ -393,6 +390,13 @@ public:
return next; return next;
} }
~argStack()
{
if (writestring != NULL) {
delete [] writestring;
}
}
void put(int arg_type, int i) void put(int arg_type, int i)
{ {
argtype = arg_type; argtype = arg_type;
@ -436,7 +440,9 @@ public:
switch (argtype) switch (argtype)
{ {
case arg_string: case arg_string:
writestring.append((char *)sz); delete [] writestring;
writestring = new char[strlen(sz)+1];
strcpy(writestring, sz);
break; break;
} }
} }
@ -464,7 +470,7 @@ public:
WRITE_COORD(writecoord); WRITE_COORD(writecoord);
break; break;
case arg_string: case arg_string:
WRITE_STRING(writestring.c_str()); WRITE_STRING(writestring);
break; break;
case arg_entity: case arg_entity:
WRITE_ENTITY(writeentity); WRITE_ENTITY(writeentity);
@ -515,7 +521,7 @@ public:
switch (argtype) switch (argtype)
{ {
case arg_string: case arg_string:
return (writestring.length()); return strlen(writestring);
break; break;
} }
return 0; return 0;
@ -526,7 +532,7 @@ public:
switch (argtype) switch (argtype)
{ {
case arg_string: case arg_string:
return writestring.c_str(); return (const char*)writestring;
break; break;
} }
@ -720,6 +726,20 @@ public:
} }
} }
void destroy()
{
argStack *p;
while (next != NULL) {
p = next->link();
delete next;
next = p;
}
if (p != NULL) {
delete p;
p = NULL;
}
}
private: private:
int argtype; int argtype;
int writebyte; int writebyte;
@ -728,7 +748,7 @@ private:
int writelong; int writelong;
float writeangle; float writeangle;
float writecoord; float writecoord;
std::string writestring; char *writestring;
int writeentity; int writeentity;
argStack *next; argStack *next;
}; };
@ -808,16 +828,9 @@ public:
void Destroy() void Destroy()
{ {
argStack *p; CHeadArg->destroy();
delete CHeadArg;
p = CHeadArg->link(); CHeadArg = NULL;
while (p) {
argStack *n = p->link();
delete p;
p = n;
}
argcount = 0;
} }
bool Set(int n, int arg_type, int data) bool Set(int n, int arg_type, int data)

View File

@ -42,12 +42,8 @@
#include <limits.h> #include <limits.h>
#include "engine.h" #include "engine.h"
extern "C" void destroy(MessageInfo* p) {
delete p;
}
GlobalInfo GlInfo; GlobalInfo GlInfo;
MessageInfo *msgd; MessageInfo *msgd = NULL;
bool isMsgHooked[MAX_MESSAGES]; bool isMsgHooked[MAX_MESSAGES];
int inHookProcess; int inHookProcess;
edict_t *valid_ent(int ent); edict_t *valid_ent(int ent);
@ -268,16 +264,20 @@ static cell AMX_NATIVE_CALL get_msg_arg_string(AMX *amx, cell *params)
int argn = params[1]; int argn = params[1];
int iLen = 0; int iLen = 0;
char *szValue = '\0'; char *szValue = '\0';
char *szRetr;
if (inHookProcess && msgd!=NULL) { if (inHookProcess && msgd!=NULL) {
if (argn <= msgd->args() && argn > 0) { if (argn <= msgd->args() && argn > 0) {
iLen = msgd->RetArg_Strlen(argn); iLen = msgd->RetArg_Strlen(argn);
szValue = new char[iLen+1]; szValue = new char[iLen+1];
strcpy(szValue, msgd->RetArg_String(argn)); szRetr = (char *)msgd->RetArg_String(argn);
if (strlen(szValue)) { if (szRetr != NULL) {
return SET_AMXSTRING(amx, params[2], szValue, params[3]); strcpy(szValue, szRetr);
} else { if (strlen(szValue)) {
return SET_AMXSTRING(amx, params[2], "", params[3]); return SET_AMXSTRING(amx, params[2], szValue, params[3]);
} else {
return SET_AMXSTRING(amx, params[2], "", params[3]);
}
} }
} else { } else {
AMX_RAISEERROR(amx, AMX_ERR_NATIVE); AMX_RAISEERROR(amx, AMX_ERR_NATIVE);
@ -2943,7 +2943,7 @@ void MessageEnd(void) {
msgd->SendMsg(); msgd->SendMsg();
RETURN_META(MRES_SUPERCEDE); RETURN_META(MRES_SUPERCEDE);
} }
destroy(msgd); delete msgd;
msgd = NULL; msgd = NULL;
} }
@ -3106,7 +3106,7 @@ void ServerDeactivate() {
} }
if (msgd != NULL) { if (msgd != NULL) {
destroy(msgd); delete msgd;
msgd = NULL; msgd = NULL;
} }