Memory leak fixes.
This commit is contained in:
parent
ed438db279
commit
7ba4dcf26c
|
@ -60,8 +60,6 @@ void initBattle(void)
|
|||
|
||||
initStars();
|
||||
|
||||
initBullets();
|
||||
|
||||
initBackground();
|
||||
|
||||
initEffects();
|
||||
|
|
|
@ -54,6 +54,7 @@ void loadItemDefs(void)
|
|||
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
|
||||
|
||||
defTail->next = e;
|
||||
defTail = e;
|
||||
}
|
||||
|
||||
cJSON_Delete(root);
|
||||
|
|
|
@ -24,8 +24,6 @@ static Entity **candidates;
|
|||
static int cIndex;
|
||||
static int cCapacity;
|
||||
|
||||
static int memory;
|
||||
|
||||
static int getIndex(Quadtree *root, int x, int y, int w, int h);
|
||||
static void removeEntity(Entity *e, Quadtree *root);
|
||||
static int candidatesComparator(const void *a, const void *b);
|
||||
|
@ -48,11 +46,12 @@ void initQuadtree(Quadtree *root)
|
|||
root->ents = malloc(sizeof(Entity*) * root->capacity);
|
||||
memset(root->ents, 0, sizeof(Entity*) * root->capacity);
|
||||
|
||||
memory = 0;
|
||||
cIndex = 0;
|
||||
cCapacity = QT_INITIAL_CAPACITY;
|
||||
candidates = malloc(sizeof(Entity*) * cCapacity);
|
||||
memset(candidates, 0, sizeof(Entity*) * cCapacity);
|
||||
}
|
||||
|
||||
memory += sizeof(Quadtree);
|
||||
|
||||
w = root->w / 2;
|
||||
h = root->h / 2;
|
||||
|
||||
|
@ -101,11 +100,6 @@ void initQuadtree(Quadtree *root)
|
|||
initQuadtree(node);
|
||||
}
|
||||
}
|
||||
|
||||
cIndex = 0;
|
||||
cCapacity = QT_INITIAL_CAPACITY;
|
||||
candidates = malloc(sizeof(Entity*) * cCapacity);
|
||||
memset(candidates, 0, sizeof(Entity*) * cCapacity);
|
||||
}
|
||||
|
||||
void addToQuadtree(Entity *e, Quadtree *root)
|
||||
|
@ -277,23 +271,28 @@ void destroyQuadtree(void)
|
|||
{
|
||||
destroyQuadtreeNode(&battle.quadtree);
|
||||
|
||||
free(candidates);
|
||||
if (candidates)
|
||||
{
|
||||
free(candidates);
|
||||
|
||||
candidates = NULL;
|
||||
candidates = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void destroyQuadtreeNode(Quadtree *root)
|
||||
{
|
||||
int i;
|
||||
|
||||
free(root->ents);
|
||||
|
||||
root->ents = NULL;
|
||||
|
||||
if (root->node[0])
|
||||
{
|
||||
for (i = 0 ; i < 4 ; i++)
|
||||
{
|
||||
destroyQuadtreeNode(root->node[i]);
|
||||
|
||||
free(root->node[i]->ents);
|
||||
|
||||
free(root->node[i]);
|
||||
|
||||
root->node[i] = NULL;
|
||||
|
|
|
@ -198,6 +198,8 @@ void loadMission(char *filename)
|
|||
|
||||
srand(time(NULL));
|
||||
|
||||
cJSON_Delete(root);
|
||||
|
||||
free(text);
|
||||
|
||||
endSectionTransition();
|
||||
|
|
|
@ -131,7 +131,6 @@ void initGameSystem(void)
|
|||
initStarSystems,
|
||||
initChallenges,
|
||||
initStats,
|
||||
initBattle,
|
||||
initModalDialog,
|
||||
initBackground,
|
||||
initControls
|
||||
|
|
|
@ -98,7 +98,20 @@ char *getMusicFilename(int i)
|
|||
|
||||
void destroyResources(void)
|
||||
{
|
||||
free(backgrounds);
|
||||
free(planets);
|
||||
free(musicFiles);
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < numBackgrounds ; i++)
|
||||
{
|
||||
free(backgrounds[i]);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < numPlanets ; i++)
|
||||
{
|
||||
free(planets[i]);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < numMusicFiles ; i++)
|
||||
{
|
||||
free(musicFiles[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -508,6 +508,8 @@ void destroyWidgets(void)
|
|||
free(w->options[i]);
|
||||
}
|
||||
|
||||
free(w->options);
|
||||
|
||||
next = w->next;
|
||||
free(w);
|
||||
w = next;
|
||||
|
|
Loading…
Reference in New Issue