aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2007-12-02 13:30:12 +0000
committertma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2007-12-02 13:30:12 +0000
commit32fdadf9367f4d480aa8f6732869fa6bb86f017a (patch)
tree46008eca3f8283d8c6257bcb7dffba4df0a3c71d
parent92b8d2cdf69e9eccb6b877ed90aa5cd829b087c2 (diff)
downloadioquake3-aero-32fdadf9367f4d480aa8f6732869fa6bb86f017a.tar.gz
ioquake3-aero-32fdadf9367f4d480aa8f6732869fa6bb86f017a.zip
* Make some botlib memory allocations /potentially/ safer
git-svn-id: svn://svn.icculus.org/quake3/trunk@1225 edf5b092-35ff-0310-97b2-ce42778d08ea
-rw-r--r--code/botlib/l_libvar.c5
-rw-r--r--code/botlib/l_precomp.c13
2 files changed, 10 insertions, 8 deletions
diff --git a/code/botlib/l_libvar.c b/code/botlib/l_libvar.c
index 4277544..0270781 100644
--- a/code/botlib/l_libvar.c
+++ b/code/botlib/l_libvar.c
@@ -84,9 +84,9 @@ libvar_t *LibVarAlloc(char *var_name)
{
libvar_t *v;
- v = (libvar_t *) GetMemory(sizeof(libvar_t) + strlen(var_name) + 1);
+ v = (libvar_t *) GetMemory(sizeof(libvar_t));
Com_Memset(v, 0, sizeof(libvar_t));
- v->name = (char *) v + sizeof(libvar_t);
+ v->name = (char *) GetMemory(strlen(var_name)+1);
strcpy(v->name, var_name);
//add the variable in the list
v->next = libvarlist;
@@ -102,6 +102,7 @@ libvar_t *LibVarAlloc(char *var_name)
void LibVarDeAlloc(libvar_t *v)
{
if (v->string) FreeMemory(v->string);
+ FreeMemory(v->name);
FreeMemory(v);
} //end of the function LibVarDeAlloc
//===========================================================================
diff --git a/code/botlib/l_precomp.c b/code/botlib/l_precomp.c
index 8b5e4d3..866a601 100644
--- a/code/botlib/l_precomp.c
+++ b/code/botlib/l_precomp.c
@@ -653,6 +653,7 @@ void PC_FreeDefine(define_t *define)
PC_FreeToken(t);
} //end for
//free the define
+ FreeMemory(define->name);
FreeMemory(define);
} //end of the function PC_FreeDefine
//============================================================================
@@ -680,9 +681,9 @@ void PC_AddBuiltinDefines(source_t *source)
for (i = 0; builtin[i].string; i++)
{
- define = (define_t *) GetMemory(sizeof(define_t) + strlen(builtin[i].string) + 1);
+ define = (define_t *) GetMemory(sizeof(define_t));
Com_Memset(define, 0, sizeof(define_t));
- define->name = (char *) define + sizeof(define_t);
+ define->name = (char *) GetMemory(strlen(builtin[i].string) + 1);
strcpy(define->name, builtin[i].string);
define->flags |= DEFINE_FIXED;
define->builtin = builtin[i].builtin;
@@ -1216,9 +1217,9 @@ int PC_Directive_define(source_t *source)
#endif //DEFINEHASHING
} //end if
//allocate define
- define = (define_t *) GetMemory(sizeof(define_t) + strlen(token.string) + 1);
+ define = (define_t *) GetMemory(sizeof(define_t));
Com_Memset(define, 0, sizeof(define_t));
- define->name = (char *) define + sizeof(define_t);
+ define->name = (char *) GetMemory(strlen(token.string) + 1);
strcpy(define->name, token.string);
//add the define to the source
#if DEFINEHASHING
@@ -1452,9 +1453,9 @@ define_t *PC_CopyDefine(source_t *source, define_t *define)
define_t *newdefine;
token_t *token, *newtoken, *lasttoken;
- newdefine = (define_t *) GetMemory(sizeof(define_t) + strlen(define->name) + 1);
+ newdefine = (define_t *) GetMemory(sizeof(define_t));
//copy the define name
- newdefine->name = (char *) newdefine + sizeof(define_t);
+ newdefine->name = (char *) GetMemory(strlen(define->name) + 1);
strcpy(newdefine->name, define->name);
newdefine->flags = define->flags;
newdefine->builtin = define->builtin;