From ac723954c7b1d01de519a8dc64a55a30faf6edb9 Mon Sep 17 00:00:00 2001 From: black Date: Thu, 21 Oct 2004 17:44:34 +0000 Subject: [PATCH] - Added Mem_IsAllocated. - Decreased the required parameter count of VM_strcat to 1. - Added a check to VM_strunzone so it wont free already freed strings and thus crash the qc (only if developer != 0). git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4691 d7cf8633-e32d-0410-b094-e92efae38249 --- prvm_cmds.c | 11 ++++++++--- zone.c | 13 +++++++++++++ zone.h | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/prvm_cmds.c b/prvm_cmds.c index 01902dbe..c9ecfc4f 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -1912,8 +1912,8 @@ void VM_strcat(void) { char *s; - if(prog->argc < 2) - PRVM_ERROR("VM_strcat wrong parameter count (min. 2 expected ) !\n"); + if(prog->argc < 1) + PRVM_ERROR("VM_strcat wrong parameter count (min. 1 expected ) !\n"); s = VM_GetTempString(); VM_VarString(0, s, VM_STRINGTEMP_LENGTH); @@ -1997,9 +1997,14 @@ strunzone(string s) //void(string s) strunzone = #119; // removes a copy of a string from the string zone (you can not use that string again or it may crash!!!) void VM_strunzone(void) { + char *str; VM_SAFEPARMCOUNT(1,VM_strunzone); - Mem_Free(PRVM_G_STRING(OFS_PARM0)); + str = PRVM_G_STRING(OFS_PARM0); + if( developer.integer && !Mem_IsAllocated( VM_STRINGS_MEMPOOL, str ) ) + PRVM_ERROR( "VM_strunzone: Zone string already freed in %s!", PRVM_NAME ); + else + Mem_Free( str ); } /* diff --git a/zone.c b/zone.c index 03a6bfa3..f58aa54a 100644 --- a/zone.c +++ b/zone.c @@ -330,6 +330,19 @@ void _Mem_CheckSentinelsGlobal(const char *filename, int fileline) #endif } +qboolean Mem_IsAllocated(mempool_t *pool, void *data) +{ + memheader_t *header; + memheader_t *target; + + target = (memheader_t *)((qbyte *) data - sizeof(memheader_t)); + for( header = pool->chain ; header ; header = header->next ) + if( header == target ) + return true; + return false; +} + + // used for temporary memory allocations around the engine, not for longterm // storage, if anything in this pool stays allocated during gameplay, it is // considered a leak diff --git a/zone.h b/zone.h index f47561c2..f1417350 100644 --- a/zone.h +++ b/zone.h @@ -132,6 +132,7 @@ void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline); void _Mem_EmptyPool(mempool_t *pool, const char *filename, int fileline); void _Mem_CheckSentinels(void *data, const char *filename, int fileline); void _Mem_CheckSentinelsGlobal(const char *filename, int fileline); +qboolean Mem_IsAllocated(mempool_t *pool, void *data); // used for temporary allocations mempool_t *tempmempool; -- 2.39.2