move freeing the gamestate's name outside of CloseGamestate

...and fixup the last commit
This commit is contained in:
Sebastian Krzyszkowiak 2019-05-11 00:44:45 +02:00
parent 6e8670bf12
commit 3b3253ab6f
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 5 additions and 3 deletions

View file

@ -413,7 +413,6 @@ 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;
}
@ -421,12 +420,15 @@ SYMBOL_INTERNAL void CloseGamestate(struct Game* game, struct Gamestate* gamesta
#ifndef LEAK_SANITIZER
PrintConsole(game, "Closing gamestate \"%s\"...", gamestate->name);
dlclose(gamestate->handle);
gamestate->handle = NULL;
#endif
}
if (gamestate->api) {
free(gamestate->api);
gamestate->api = NULL;
}
al_destroy_bitmap(gamestate->fb);
gamestate->fb = NULL;
}
SYMBOL_INTERNAL struct List* AddToList(struct List* list, void* data) {
@ -619,9 +621,7 @@ SYMBOL_INTERNAL void ReloadCode(struct Game* game) {
struct Gamestate* tmp = game->_priv.gamestates;
while (tmp) {
if (tmp->open && tmp->fromlib) {
char* name = strdup(tmp->name);
CloseGamestate(game, tmp);
tmp->name = name;
if (OpenGamestate(game, tmp, true) && LinkGamestate(game, tmp) && tmp->loaded) {
if (tmp->api->reload) {
PrintConsole(game, "[%s] Reloading...", tmp->name);

View file

@ -481,6 +481,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
}
CloseGamestate(game, tmp);
pom = tmp->next;
free(tmp->name);
free(tmp);
tmp = pom;
}
@ -489,6 +490,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
(*game->_priv.loading.gamestate->api->unload)(game, game->_priv.loading.gamestate->data);
}
CloseGamestate(game, game->_priv.loading.gamestate);
free(game->_priv.loading.gamestate->name);
free(game->_priv.loading.gamestate);
if (game->_priv.params.handlers.destroy) {