diff --git a/src/design.c b/src/design.c index 7aa2a44ca..884b777ae 100644 --- a/src/design.c +++ b/src/design.c @@ -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; } diff --git a/src/droid.c b/src/droid.c index 181fbde2e..8d4897bd5 100644 --- a/src/droid.c +++ b/src/droid.c @@ -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; } diff --git a/src/game.c b/src/game.c index cd77a4c9a..ec704a81d 100644 --- a/src/game.c +++ b/src/game.c @@ -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; } diff --git a/src/multiopt.c b/src/multiopt.c index 8295189d9..82874254b 100644 --- a/src/multiopt.c +++ b/src/multiopt.c @@ -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; } diff --git a/src/multiplay.c b/src/multiplay.c index c5aed0761..1df0a69fd 100644 --- a/src/multiplay.c +++ b/src/multiplay.c @@ -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); } diff --git a/src/multistat.c b/src/multistat.c index f12787b2e..8ca240112 100644 --- a/src/multistat.c +++ b/src/multistat.c @@ -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(); diff --git a/src/objmem.c b/src/objmem.c index bab2bd3f0..4cc65b63a 100644 --- a/src/objmem.c +++ b/src/objmem.c @@ -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 */ diff --git a/src/objmem.h b/src/objmem.h index 511afa6a0..13ff06f13 100644 --- a/src/objmem.h +++ b/src/objmem.h @@ -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]; diff --git a/src/scriptai.c b/src/scriptai.c index 1c136da3e..68cc7ea06 100644 --- a/src/scriptai.c +++ b/src/scriptai.c @@ -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]); } } diff --git a/src/scriptfuncs.c b/src/scriptfuncs.c index 83f3f0e2b..f1aafe6d6 100644 --- a/src/scriptfuncs.c +++ b/src/scriptfuncs.c @@ -6714,7 +6714,7 @@ BOOL scrTutorialTemplates(void) // Delete the template. if(psCurr) { - HEAP_FREE(psTemplateHeap, psCurr); + free(psCurr); } else {