]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
mempools now have sentinel checks, for completeness
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 6 Sep 2002 16:51:51 +0000 (16:51 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 6 Sep 2002 16:51:51 +0000 (16:51 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2342 d7cf8633-e32d-0410-b094-e92efae38249

zone.c
zone.h

diff --git a/zone.c b/zone.c
index f5fdf73c224463d742da7e2067b8a15dd7d465a3..db9952ffecd58eac20c4facc10208841e1874c2f 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -201,6 +201,10 @@ mempool_t *_Mem_AllocPool(char *name, char *filename, int fileline)
        if (pool == NULL)
                Sys_Error("Mem_AllocPool: out of memory (allocpool at %s:%i)", filename, fileline);
        memset(pool, 0, sizeof(mempool_t));
+       pool->sentinel1 = MEMHEADER_SENTINEL1;
+       pool->sentinel2 = MEMHEADER_SENTINEL1;
+       pool->filename = filename;
+       pool->fileline = fileline;
        pool->chain = NULL;
        pool->totalsize = 0;
        pool->realsize = sizeof(mempool_t);
@@ -215,6 +219,10 @@ void _Mem_FreePool(mempool_t **pool, char *filename, int fileline)
        mempool_t **chainaddress;
        if (*pool)
        {
+               if ((*pool)->sentinel1 != MEMHEADER_SENTINEL1)
+                       Sys_Error("Mem_FreePool: trashed pool sentinel 1 (allocpool at %s:%i, freepool at %s:%i)", (*pool)->filename, (*pool)->fileline, filename, fileline);
+               if ((*pool)->sentinel2 != MEMHEADER_SENTINEL1)
+                       Sys_Error("Mem_FreePool: trashed pool sentinel 2 (allocpool at %s:%i, freepool at %s:%i)", (*pool)->filename, (*pool)->fileline, filename, fileline);
                // unlink pool from chain
                for (chainaddress = &poolchain;*chainaddress && *chainaddress != *pool;chainaddress = &((*chainaddress)->next));
                if (*chainaddress != *pool)
@@ -236,6 +244,10 @@ void _Mem_EmptyPool(mempool_t *pool, char *filename, int fileline)
 {
        if (pool == NULL)
                Sys_Error("Mem_EmptyPool: pool == NULL (emptypool at %s:%i)", filename, fileline);
+       if (pool->sentinel1 != MEMHEADER_SENTINEL1)
+               Sys_Error("Mem_EmptyPool: trashed pool sentinel 1 (allocpool at %s:%i, emptypool at %s:%i)", pool->filename, pool->fileline, filename, fileline);
+       if (pool->sentinel2 != MEMHEADER_SENTINEL1)
+               Sys_Error("Mem_EmptyPool: trashed pool sentinel 2 (allocpool at %s:%i, emptypool at %s:%i)", pool->filename, pool->fileline, filename, fileline);
 
        // free memory owned by the pool
        while (pool->chain)
@@ -275,15 +287,19 @@ void _Mem_CheckSentinelsGlobal(char *filename, int fileline)
 #endif
        mempool_t *pool;
        for (pool = poolchain;pool;pool = pool->next)
-#if MEMCLUMPING
        {
-#endif
+               if (pool->sentinel1 != MEMHEADER_SENTINEL1)
+                       Sys_Error("Mem_CheckSentinelsGlobal: trashed pool sentinel 1 (allocpool at %s:%i, sentinel check at %s:%i)", pool->filename, pool->fileline, filename, fileline);
+               if (pool->sentinel2 != MEMHEADER_SENTINEL1)
+                       Sys_Error("Mem_CheckSentinelsGlobal: trashed pool sentinel 2 (allocpool at %s:%i, sentinel check at %s:%i)", pool->filename, pool->fileline, filename, fileline);
+       }
+       for (pool = poolchain;pool;pool = pool->next)
                for (mem = pool->chain;mem;mem = mem->chain)
                        _Mem_CheckSentinels((void *)((qbyte *) mem + sizeof(memheader_t)), filename, fileline);
 #if MEMCLUMPING
+       for (pool = poolchain;pool;pool = pool->next)
                for (clump = pool->clumpchain;clump;clump = clump->chain)
                        _Mem_CheckClumpSentinels(clump, filename, fileline);
-       }
 #endif
 }
 
diff --git a/zone.h b/zone.h
index 9cdd9ff93e8620c259cd0f032094c5d453f1a13c..c76867d24e164879ed5550c1b2b9fccf364cb210 100644 (file)
--- a/zone.h
+++ b/zone.h
@@ -84,6 +84,8 @@ memclump_t;
 
 typedef struct mempool_s
 {
+       // should always be MEMHEADER_SENTINEL1
+       int sentinel1;
        // chain of individual memory allocations
        struct memheader_s *chain;
 #if MEMCLUMPING
@@ -100,6 +102,11 @@ typedef struct mempool_s
        char name[POOLNAMESIZE];
        // linked into global mempool list
        struct mempool_s *next;
+       // file name and line where Mem_AllocPool was called
+       char *filename;
+       int fileline;
+       // should always be MEMHEADER_SENTINEL1
+       int sentinel2;
 }
 mempool_t;