(svn r23901) -Fix: memory leak everytime one clicked a savegame in the load GUI

This commit is contained in:
smatz 2012-02-05 15:51:13 +00:00
parent fbf29d5da8
commit eb015cbfb6
3 changed files with 17 additions and 8 deletions

View File

@ -27,6 +27,7 @@
#include "landscape_type.h" #include "landscape_type.h"
#include "date_func.h" #include "date_func.h"
#include "core/geometry_func.hpp" #include "core/geometry_func.hpp"
#include "gamelog.h"
#include "widgets/fios_widget.h" #include "widgets/fios_widget.h"
@ -60,7 +61,7 @@ void LoadCheckData::Clear()
} }
companies.Clear(); companies.Clear();
free(this->gamelog_action); GamelogFree(this->gamelog_action, this->gamelog_actions);
this->gamelog_action = NULL; this->gamelog_action = NULL;
this->gamelog_actions = 0; this->gamelog_actions = 0;

View File

@ -64,14 +64,12 @@ void GamelogStopAction()
} }
/** /**
* Resets and frees all memory allocated - used before loading or starting a new game * Frees the memory allocated by a gamelog
*/ */
void GamelogReset() void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
{ {
assert(_gamelog_action_type == GLAT_NONE); for (uint i = 0; i < gamelog_actions; i++) {
const LoggedAction *la = &gamelog_action[i];
for (uint i = 0; i < _gamelog_actions; i++) {
const LoggedAction *la = &_gamelog_action[i];
for (uint j = 0; j < la->changes; j++) { for (uint j = 0; j < la->changes; j++) {
const LoggedChange *lc = &la->change[j]; const LoggedChange *lc = &la->change[j];
if (lc->ct == GLCT_SETTING) free(lc->setting.name); if (lc->ct == GLCT_SETTING) free(lc->setting.name);
@ -79,7 +77,16 @@ void GamelogReset()
free(la->change); free(la->change);
} }
free(_gamelog_action); free(gamelog_action);
}
/**
* Resets and frees all memory allocated - used before loading or starting a new game
*/
void GamelogReset()
{
assert(_gamelog_action_type == GLAT_NONE);
GamelogFree(_gamelog_action, _gamelog_actions);
_gamelog_action = NULL; _gamelog_action = NULL;
_gamelog_actions = 0; _gamelog_actions = 0;

View File

@ -30,6 +30,7 @@ enum GamelogActionType {
void GamelogStartAction(GamelogActionType at); void GamelogStartAction(GamelogActionType at);
void GamelogStopAction(); void GamelogStopAction();
void GamelogFree(struct LoggedAction *gamelog_action, uint gamelog_actions);
void GamelogReset(); void GamelogReset();
/** /**