From eb015cbfb62451313d99fa4829d9a712411bf002 Mon Sep 17 00:00:00 2001 From: smatz Date: Sun, 5 Feb 2012 15:51:13 +0000 Subject: (svn r23901) -Fix: memory leak everytime one clicked a savegame in the load GUI --- src/fios_gui.cpp | 3 ++- src/gamelog.cpp | 21 ++++++++++++++------- src/gamelog.h | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 3e48c10bb..5ae42897f 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -27,6 +27,7 @@ #include "landscape_type.h" #include "date_func.h" #include "core/geometry_func.hpp" +#include "gamelog.h" #include "widgets/fios_widget.h" @@ -60,7 +61,7 @@ void LoadCheckData::Clear() } companies.Clear(); - free(this->gamelog_action); + GamelogFree(this->gamelog_action, this->gamelog_actions); this->gamelog_action = NULL; this->gamelog_actions = 0; diff --git a/src/gamelog.cpp b/src/gamelog.cpp index f4f009166..b4b9fd7a6 100644 --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -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++) { const LoggedChange *lc = &la->change[j]; if (lc->ct == GLCT_SETTING) free(lc->setting.name); @@ -79,7 +77,16 @@ void GamelogReset() 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_actions = 0; diff --git a/src/gamelog.h b/src/gamelog.h index 8357cb90a..7f5b6a776 100644 --- a/src/gamelog.h +++ b/src/gamelog.h @@ -30,6 +30,7 @@ enum GamelogActionType { void GamelogStartAction(GamelogActionType at); void GamelogStopAction(); +void GamelogFree(struct LoggedAction *gamelog_action, uint gamelog_actions); void GamelogReset(); /** -- cgit v1.2.3-70-g09d2