]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
- Added Mem_IsAllocated.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 21 Oct 2004 17:44:34 +0000 (17:44 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 21 Oct 2004 17:44:34 +0000 (17:44 +0000)
- 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
zone.c
zone.h

index 01902dbe5dc2fd8cbec2b44debff8cf1f377bf4f..c9ecfc4ff80e9aacc346085a7d6fbd9e5677c5b2 100644 (file)
@@ -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 03a6bfa3d0a029880641616d42abd802eb5dadc9..f58aa54a38a94d8356088ecb87dfd5834d9ca862 100644 (file)
--- 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 f47561c2f30fb82bbbf8427c12930b9e67aa83ff..f1417350b1f946931a1f440b848bd683c13d3774 100644 (file)
--- 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;