fix a memory leak happening when there's no loading gamestate registered

This commit is contained in:
Sebastian Krzyszkowiak 2019-05-11 00:05:40 +02:00
parent 2b3a2e3d72
commit 6e8670bf12
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 11 additions and 9 deletions

View file

@ -162,15 +162,17 @@ SYMBOL_INTERNAL void UnfreezeGamestates(struct Game* game) {
SYMBOL_INTERNAL void ResizeGamestates(struct Game* game) {
struct Gamestate* tmp = game->_priv.gamestates;
while (tmp) {
al_destroy_bitmap(tmp->fb);
if (game->_priv.params.handlers.compositor) {
tmp->fb = CreateNotPreservedBitmap(game->clip_rect.w, game->clip_rect.h);
} else {
tmp->fb = al_create_sub_bitmap(al_get_backbuffer(game->display), game->clip_rect.x, game->clip_rect.y, game->clip_rect.w, game->clip_rect.h);
if (tmp->open) {
al_destroy_bitmap(tmp->fb);
if (game->_priv.params.handlers.compositor) {
tmp->fb = CreateNotPreservedBitmap(game->clip_rect.w, game->clip_rect.h);
} else {
tmp->fb = al_create_sub_bitmap(al_get_backbuffer(game->display), game->clip_rect.x, game->clip_rect.y, game->clip_rect.w, game->clip_rect.h);
}
}
tmp = tmp->next;
}
if (game->_priv.loading.gamestate) {
if (game->_priv.loading.gamestate && game->_priv.loading.gamestate->open) {
al_destroy_bitmap(game->_priv.loading.gamestate->fb);
if (game->_priv.params.handlers.compositor) {
game->_priv.loading.gamestate->fb = CreateNotPreservedBitmap(game->clip_rect.w, game->clip_rect.h);
@ -411,6 +413,7 @@ SYMBOL_INTERNAL struct Gamestate* AllocateGamestate(struct Game* game, const cha
}
SYMBOL_INTERNAL void CloseGamestate(struct Game* game, struct Gamestate* gamestate) {
free(gamestate->name);
if (!gamestate->open) {
return;
}
@ -420,7 +423,6 @@ SYMBOL_INTERNAL void CloseGamestate(struct Game* game, struct Gamestate* gamesta
dlclose(gamestate->handle);
#endif
}
free(gamestate->name);
if (gamestate->api) {
free(gamestate->api);
}

View file

@ -485,10 +485,10 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
tmp = pom;
}
if (game->_priv.loading.gamestate->open) {
if (game->_priv.loading.gamestate->api) {
(*game->_priv.loading.gamestate->api->unload)(game, game->_priv.loading.gamestate->data);
CloseGamestate(game, game->_priv.loading.gamestate);
}
CloseGamestate(game, game->_priv.loading.gamestate);
free(game->_priv.loading.gamestate);
if (game->_priv.params.handlers.destroy) {