widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #11592
[Merge] lp:~flegu/widelands/fix_some_memory_leaks into lp:widelands
Jukka Pakarinen has proposed merging lp:~flegu/widelands/fix_some_memory_leaks into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~flegu/widelands/fix_some_memory_leaks/+merge/333930
There happens memory leaks detected with Valgrind in multiple menu views. The changes in the branch fixes most of the cases. The leaks were found when the game was built from trunk (revno 8490) on Debian 9.1. I think these leaks are definitely happening on every operating system.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~flegu/widelands/fix_some_memory_leaks into lp:widelands.
=== modified file 'src/ui_fsmenu/campaign_select.cc'
--- src/ui_fsmenu/campaign_select.cc 2017-03-05 17:55:29 +0000
+++ src/ui_fsmenu/campaign_select.cc 2017-11-18 07:26:04 +0000
@@ -493,4 +493,5 @@
table_.select(0);
}
set_has_selection();
+ delete prof;
}
=== modified file 'src/ui_fsmenu/loadgame.cc'
--- src/ui_fsmenu/loadgame.cc 2017-11-06 20:19:56 +0000
+++ src/ui_fsmenu/loadgame.cc 2017-11-18 07:26:04 +0000
@@ -114,7 +114,7 @@
return;
}
- const SavegameData* gamedata = load_or_save_.entry_selected();
+ const std::shared_ptr<SavegameData> gamedata = load_or_save_.entry_selected();
if (gamedata && gamedata->errormessage.empty()) {
filename_ = gamedata->filename;
end_modal<FullscreenMenuBase::MenuTarget>(FullscreenMenuBase::MenuTarget::kOk);
=== modified file 'src/ui_fsmenu/options.cc'
--- src/ui_fsmenu/options.cc 2017-11-12 08:04:06 +0000
+++ src/ui_fsmenu/options.cc 2017-11-18 07:26:04 +0000
@@ -453,6 +453,7 @@
LanguageEntry* entry = new LanguageEntry(localename, name);
entries.insert(std::make_pair(sortname, *entry));
language_entries_.insert(std::make_pair(localename, *entry));
+ delete entry;
if (localename == current_locale) {
selected_locale = current_locale;
=== modified file 'src/wui/load_or_save_game.cc'
--- src/wui/load_or_save_game.cc 2017-11-06 20:19:56 +0000
+++ src/wui/load_or_save_game.cc 2017-11-18 07:26:04 +0000
@@ -168,8 +168,8 @@
return r1.savetimestamp < r2.savetimestamp;
}
-const SavegameData* LoadOrSaveGame::entry_selected() {
- SavegameData* result = new SavegameData();
+const std::shared_ptr<SavegameData> LoadOrSaveGame::entry_selected() {
+ std::shared_ptr<SavegameData> result = std::make_shared<SavegameData>(SavegameData());
size_t selections = table_.selections().size();
if (selections == 1) {
delete_->set_tooltip(
@@ -178,7 +178,7 @@
_("Delete this replay") :
/** TRANSLATORS: Tooltip for the delete button. The user has selected 1 file */
_("Delete this game"));
- result = &games_data_[table_.get_selected()];
+ result = std::make_shared<SavegameData>(games_data_[table_.get_selected()]);
} else if (selections > 1) {
delete_->set_tooltip(
filetype_ == FileType::kReplay ?
=== modified file 'src/wui/load_or_save_game.h'
--- src/wui/load_or_save_game.h 2017-08-12 08:03:19 +0000
+++ src/wui/load_or_save_game.h 2017-11-18 07:26:04 +0000
@@ -43,7 +43,7 @@
bool localize_autosave);
/// Update gamedetails and tooltips and return information about the current selection
- const SavegameData* entry_selected();
+ const std::shared_ptr<SavegameData> entry_selected();
/// Whether the table has a selection
bool has_selection() const;
Follow ups