- pool->totalsize -= mem->size;
-#if MEMCLUMPING
- if ((clump = mem->clump))
- {
- if (clump->sentinel1 != MEMCLUMP_SENTINEL)
- Sys_Error("Mem_Free: trashed clump sentinel 1 (free at %s:%i)", filename, fileline);
- if (clump->sentinel2 != MEMCLUMP_SENTINEL)
- Sys_Error("Mem_Free: trashed clump sentinel 2 (free at %s:%i)", filename, fileline);
- firstblock = ((unsigned char *) mem - (unsigned char *) clump->block);
- if (firstblock & (MEMUNIT - 1))
- Sys_Error("Mem_Free: address not valid in clump (free at %s:%i)", filename, fileline);
- firstblock /= MEMUNIT;
- endblock = firstblock + ((sizeof(memheader_t) + mem->size + sizeof(int) + (MEMUNIT - 1)) / MEMUNIT);
- clump->blocksinuse -= endblock - firstblock;
- // could use &, but we know the bit is set
- for (i = firstblock;i < endblock;i++)
- clump->bits[i >> 5] -= (1 << (i & 31));
- if (clump->blocksinuse <= 0)
- {
- // unlink from chain
- for (clumpchainpointer = &pool->clumpchain;*clumpchainpointer;clumpchainpointer = &(*clumpchainpointer)->chain)
- {
- if (*clumpchainpointer == clump)
- {
- *clumpchainpointer = clump->chain;
- break;
- }
- }
- pool->realsize -= sizeof(memclump_t);
- memset(clump, 0xBF, sizeof(memclump_t));
- free(clump);
- }
- else
- {
- // clump still has some allocations
- // force re-check of largest available space on next alloc
- clump->largestavailable = MEMBITS - clump->blocksinuse;
- }
- }
- else
- {
-#endif
- pool->realsize -= sizeof(memheader_t) + mem->size + sizeof(int);
- if (developer_memorydebug.integer)
- memset(mem, 0xBF, sizeof(memheader_t) + mem->size + sizeof(int));
- free(mem);
-#if MEMCLUMPING
- }
-#endif
+ size = mem->size;
+ realsize = sizeof(memheader_t) + size + sizeof(sentinel2);
+ pool->totalsize -= size;
+ pool->realsize -= realsize;
+ Clump_FreeBlock(mem->baseaddress, realsize);
+ if (mem_mutex)
+ Thread_UnlockMutex(mem_mutex);