* Make some botlib memory allocations /potentially/ safer

This commit is contained in:
Tim Angus 2007-12-02 13:30:12 +00:00
parent 4f0565a4a7
commit dfc97a1dfa
2 changed files with 10 additions and 8 deletions

View file

@ -84,9 +84,9 @@ libvar_t *LibVarAlloc(char *var_name)
{ {
libvar_t *v; 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)); 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); strcpy(v->name, var_name);
//add the variable in the list //add the variable in the list
v->next = libvarlist; v->next = libvarlist;
@ -102,6 +102,7 @@ libvar_t *LibVarAlloc(char *var_name)
void LibVarDeAlloc(libvar_t *v) void LibVarDeAlloc(libvar_t *v)
{ {
if (v->string) FreeMemory(v->string); if (v->string) FreeMemory(v->string);
FreeMemory(v->name);
FreeMemory(v); FreeMemory(v);
} //end of the function LibVarDeAlloc } //end of the function LibVarDeAlloc
//=========================================================================== //===========================================================================

View file

@ -653,6 +653,7 @@ void PC_FreeDefine(define_t *define)
PC_FreeToken(t); PC_FreeToken(t);
} //end for } //end for
//free the define //free the define
FreeMemory(define->name);
FreeMemory(define); FreeMemory(define);
} //end of the function PC_FreeDefine } //end of the function PC_FreeDefine
//============================================================================ //============================================================================
@ -680,9 +681,9 @@ void PC_AddBuiltinDefines(source_t *source)
for (i = 0; builtin[i].string; i++) 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)); 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); strcpy(define->name, builtin[i].string);
define->flags |= DEFINE_FIXED; define->flags |= DEFINE_FIXED;
define->builtin = builtin[i].builtin; define->builtin = builtin[i].builtin;
@ -1216,9 +1217,9 @@ int PC_Directive_define(source_t *source)
#endif //DEFINEHASHING #endif //DEFINEHASHING
} //end if } //end if
//allocate define //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)); 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); strcpy(define->name, token.string);
//add the define to the source //add the define to the source
#if DEFINEHASHING #if DEFINEHASHING
@ -1452,9 +1453,9 @@ define_t *PC_CopyDefine(source_t *source, define_t *define)
define_t *newdefine; define_t *newdefine;
token_t *token, *newtoken, *lasttoken; 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 //copy the define name
newdefine->name = (char *) newdefine + sizeof(define_t); newdefine->name = (char *) GetMemory(strlen(define->name) + 1);
strcpy(newdefine->name, define->name); strcpy(newdefine->name, define->name);
newdefine->flags = define->flags; newdefine->flags = define->flags;
newdefine->builtin = define->builtin; newdefine->builtin = define->builtin;