Some more heap abolishing:

* Replace use of heap psTemplateHeap with malloc/free

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1817 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2007-06-05 10:15:33 +00:00
parent 7ae1b1bee7
commit 9e9a17e58f
10 changed files with 42 additions and 43 deletions

View File

@ -4695,7 +4695,7 @@ void intProcessDesign(UDWORD id)
// Delete the template.
//before deleting the template, need to make sure not being used in production
deleteTemplateFromProduction(psTempl, (UBYTE)selectedPlayer);
HEAP_FREE(psTemplateHeap, psTempl);
free(psTempl);
/* get previous template and set as current */
psTempl = apsTemplateList[i-1];
@ -5280,9 +5280,10 @@ static BOOL saveTemplate(void)
if ( psTempl == NULL )
{
/* The design needs a new template in the list */
if (!HEAP_ALLOC(psTemplateHeap, (void**) &psTempl))
psTempl = malloc(sizeof(DROID_TEMPLATE));
if (psTempl == NULL)
{
debug( LOG_NEVER, "saveTemplate: heap alloc failed\n" );
debug(LOG_ERROR, "saveTemplate: Out of memory");
return FALSE;
}

View File

@ -2331,9 +2331,10 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
for (i=0; i < NumDroids; i++)
{
if (!HEAP_ALLOC(psTemplateHeap, (void**) &pDroidDesign))
pDroidDesign = malloc(sizeof(DROID_TEMPLATE));
if (pDroidDesign == NULL)
{
debug(LOG_ERROR, "Out of memory - Droid Templates");
debug(LOG_ERROR, "loadDroidTemplates: Out of memory");
return FALSE;
}
memset(pDroidDesign, 0, sizeof(DROID_TEMPLATE));
@ -2695,7 +2696,7 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
if ( pDroidDesign->droidType == DROID_DEFAULT )
{
memcpy( &sDefaultDesignTemplate, pDroidDesign, sizeof(DROID_TEMPLATE) );
HEAP_FREE(psTemplateHeap, pDroidDesign);
free(pDroidDesign);
}
else
{
@ -3021,7 +3022,7 @@ BOOL droidTemplateShutDown(void)
pTemplate = pNext)
{
pNext = pTemplate->psNext;
HEAP_FREE(psTemplateHeap, pTemplate);
free(pTemplate);
}
apsDroidTemplates[player] = NULL;
}

View File

@ -1881,7 +1881,7 @@ BOOL loadGame(char *pGameToLoad, BOOL keepObjects, BOOL freeMem, BOOL UserSaveGa
pTemplate = pNext)
{
pNext = pTemplate->psNext;
HEAP_FREE(psTemplateHeap, pTemplate);
free(pTemplate);
}
apsDroidTemplates[0] = NULL;
}
@ -1896,7 +1896,7 @@ BOOL loadGame(char *pGameToLoad, BOOL keepObjects, BOOL freeMem, BOOL UserSaveGa
{
DROID_TEMPLATE *psTempl;
psTempl = apsDroidTemplates[inc]->psNext;
HEAP_FREE(psTemplateHeap, apsDroidTemplates[inc]);
free(apsDroidTemplates[inc]);
apsDroidTemplates[inc] = psTempl;
}
}
@ -8438,9 +8438,10 @@ BOOL loadSaveTemplateV7(char *pFileData, UDWORD filesize, UDWORD numTemplates)
}
//create the Template
if (!HEAP_ALLOC(psTemplateHeap, (void**) &psTemplate))
psTemplate = malloc(sizeof(DROID_TEMPLATE));
if (psTemplate == NULL)
{
debug( LOG_ERROR, "Out of memory" );
debug(LOG_ERROR, "loadSaveTemplateV7: Out of memory");
abort();
goto error;
}
@ -8479,7 +8480,7 @@ BOOL loadSaveTemplateV7(char *pFileData, UDWORD filesize, UDWORD numTemplates)
if (!found)
{
//ignore this record
HEAP_FREE(psTemplateHeap, psTemplate);
free(psTemplate);
continue;
}
psTemplate->numWeaps = psSaveTemplate->numWeaps;
@ -8504,7 +8505,7 @@ BOOL loadSaveTemplateV7(char *pFileData, UDWORD filesize, UDWORD numTemplates)
if (!found)
{
//ignore this record
HEAP_FREE(psTemplateHeap, psTemplate);
free(psTemplate);
continue;
}
@ -8570,9 +8571,10 @@ BOOL loadSaveTemplateV14(char *pFileData, UDWORD filesize, UDWORD numTemplates)
}
//create the Template
if (!HEAP_ALLOC(psTemplateHeap, (void**) &psTemplate))
psTemplate = malloc(sizeof(DROID_TEMPLATE));
if (psTemplate == NULL)
{
debug( LOG_ERROR, "Out of memory" );
debug(LOG_ERROR, "loadSaveTemplateV14: Out of memory");
abort();
goto error;
}
@ -8613,7 +8615,7 @@ BOOL loadSaveTemplateV14(char *pFileData, UDWORD filesize, UDWORD numTemplates)
if (!found)
{
//ignore this record
HEAP_FREE(psTemplateHeap, psTemplate);
free(psTemplate);
continue;
}
psTemplate->numWeaps = psSaveTemplate->numWeaps;
@ -8637,7 +8639,7 @@ BOOL loadSaveTemplateV14(char *pFileData, UDWORD filesize, UDWORD numTemplates)
if (!found)
{
//ignore this record
HEAP_FREE(psTemplateHeap, psTemplate);
free(psTemplate);
continue;
}
@ -8733,9 +8735,10 @@ BOOL loadSaveTemplateV(char *pFileData, UDWORD filesize, UDWORD numTemplates)
}
//create the Template
if (!HEAP_ALLOC(psTemplateHeap, (void**) &psTemplate))
psTemplate = malloc(sizeof(DROID_TEMPLATE));
if (psTemplate == NULL)
{
debug( LOG_ERROR, "Out of memory" );
debug(LOG_ERROR, "loadSaveTemplateV: Out of memory");
abort();
goto error;
}
@ -8793,7 +8796,7 @@ BOOL loadSaveTemplateV(char *pFileData, UDWORD filesize, UDWORD numTemplates)
if (!found)
{
//ignore this record
HEAP_FREE(psTemplateHeap, psTemplate);
free(psTemplate);
continue;
}
psTemplate->numWeaps = psSaveTemplate->numWeaps;
@ -8819,7 +8822,7 @@ BOOL loadSaveTemplateV(char *pFileData, UDWORD filesize, UDWORD numTemplates)
if (!found)
{
//ignore this record
HEAP_FREE(psTemplateHeap, psTemplate);
free(psTemplate);
continue;
}

View File

@ -556,10 +556,11 @@ BOOL multiShutdown(void)
BOOL addTemplate(UDWORD player, DROID_TEMPLATE *psNew)
{
DROID_TEMPLATE *psTempl;
DROID_TEMPLATE *psTempl = malloc(sizeof(DROID_TEMPLATE));
if (!HEAP_ALLOC(psTemplateHeap, (void**) &psTempl))
if (psTempl == NULL)
{
debug(LOG_ERROR, "addTemplate: Out of memory");
return FALSE;
}
memcpy(psTempl, psNew, sizeof(DROID_TEMPLATE));
@ -604,7 +605,7 @@ BOOL copyTemplateSet(UDWORD from,UDWORD to)
while(apsDroidTemplates[to]) // clear the old template out.
{
psTempl = apsDroidTemplates[to]->psNext;
HEAP_FREE(psTemplateHeap, apsDroidTemplates[to]);
free(apsDroidTemplates[to]);
apsDroidTemplates[to] = psTempl;
}

View File

@ -1394,8 +1394,11 @@ BOOL recvTemplate(NETMSG * m)
addTemplate(player,&t);
apsDroidTemplates[player]->ref = REF_TEMPLATE_START; // templates are the odd one out!
/* if (!HEAP_ALLOC(psTemplateHeap, &psTempl))
#if 0
psTempl = malloc(sizeof(DROID_TEMPLATE));
if (psTempl == NULL)
{
debug(LOG_ERROR, "recvTemplate: Out of memory");
return FALSE;
}
memcpy(psTempl, &t, sizeof(DROID_TEMPLATE));
@ -1415,7 +1418,7 @@ BOOL recvTemplate(NETMSG * m)
apsDroidTemplates[player]=psTempl;
psTempl->psNext = NULL;
}
*/
#endif
}
return TRUE;
}
@ -1467,7 +1470,7 @@ static BOOL recvDestroyTemplate(NETMSG * m)
{
apsDroidTemplates[player] = psTempl->psNext;// It's at the root ?
}
HEAP_FREE(psTemplateHeap, psTempl); // Delete the template.
free(psTempl); // Delete the template.
}
return (TRUE);
}

View File

@ -290,7 +290,8 @@ void useTheForce(BOOL bAddTempl)//Luke
/* if(!psTempl) // already exists.
{
if (HEAP_ALLOC(psTemplateHeap, &psTempl))
psTempl = malloc(sizeof(DROID_TEMPLATE));
if (psTempl != NULL)
{
memcpy(psTempl, Force.pMembers->pTempl, sizeof(DROID_TEMPLATE));
psTempl->ref = REF_TEMPLATE_START; // templates are the odd one out!
@ -469,7 +470,7 @@ BOOL loadForce(char *name)
for(tcount;tcount!=0;tcount--) // get templates
{
psTempl = malloc(sizeof(DROID_TEMPLATE));
if (psTempl == NULL) // !HEAP_ALLOC(psTemplateHeap, &psTempl))
if (psTempl == NULL)
{
debug( LOG_ERROR, "Couldn't allocate template for %s", fileName );
abort();

View File

@ -65,8 +65,6 @@ OBJ_HEAP *psDroidHeap, *psStructHeap, *psFeatureHeap;
OBJ_HEAP *psStructFuncHeap;
/* The memory heap for the Flag Postions */
OBJ_HEAP *psFlagPosHeap;
// the memory heap for templates
OBJ_HEAP *psTemplateHeap;
//SDWORD factoryDeliveryPointCheck[MAX_PLAYERS][NUM_FACTORY_TYPES][MAX_FACTORY];
@ -210,11 +208,6 @@ BOOL objmemInitialise(void)
return FALSE;
}
if (!HEAP_CREATE(&psTemplateHeap, sizeof(DROID_TEMPLATE), TEMPLATE_INIT, TEMPLATE_EXT))
{
return FALSE;
}
// reset the object ID number
objID = OBJ_ID_INIT;
@ -231,7 +224,6 @@ void objmemShutdown(void)
HEAP_DESTROY(psStructFuncHeap);
HEAP_DESTROY(psFeatureHeap);
HEAP_DESTROY(psFlagPosHeap);
HEAP_DESTROY(psTemplateHeap);
}
/* General housekeeping for the object system */

View File

@ -34,9 +34,6 @@
/* The memory heaps for the different object types */
extern OBJ_HEAP *psDroidHeap, *psStructHeap, *psFeatureHeap;
// the memory heap for templates
extern OBJ_HEAP *psTemplateHeap;
/* The lists of objects allocated */
extern DROID *apsDroidLists[MAX_PLAYERS];
extern STRUCTURE *apsStructLists[MAX_PLAYERS];

View File

@ -2263,7 +2263,7 @@ BOOL skAddTemplate(void)
}
psTempl =(DROID_TEMPLATE *)stempl;
// psT = malloc(sizeof(SKIRMISHSTORE));
HEAP_ALLOC(psTemplateHeap,&psT);
psT = malloc(sizeof(DROID_TEMPLATE));
if ( !psT)
{
goto fail;
@ -2322,7 +2322,7 @@ BOOL skClearSkirmishTemplates(void)
{
while(skirmishStore[i])
{
HEAP_FREE(psTemplateHeap,skirmishStore[i]);
free(skirmishStore[i]);
}
}

View File

@ -6714,7 +6714,7 @@ BOOL scrTutorialTemplates(void)
// Delete the template.
if(psCurr)
{
HEAP_FREE(psTemplateHeap, psCurr);
free(psCurr);
}
else
{