Merge lp:~flegu/widelands/fix_some_memory_leaks into lp:widelands
- fix_some_memory_leaks
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 8495 |
Proposed branch: | lp:~flegu/widelands/fix_some_memory_leaks |
Merge into: | lp:widelands |
Diff against target: |
114 lines (+14/-9) 5 files modified
src/ui_fsmenu/campaign_select.cc (+3/-3) src/ui_fsmenu/loadgame.cc (+3/-1) src/ui_fsmenu/options.cc (+1/-1) src/wui/load_or_save_game.cc (+4/-3) src/wui/load_or_save_game.h (+3/-1) |
To merge this branch: | bzr merge lp:~flegu/widelands/fix_some_memory_leaks |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
SirVer | Approve | ||
Klaus Halfmann | compile, test, review | Approve | |
Review via email: mp+333930@code.launchpad.net |
Commit message
Description of the change
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.
Klaus Halfmann (klaus-halfmann) wrote : | # |
Klaus Halfmann (klaus-halfmann) wrote : | # |
Compiled and tested all Dialogs I could think for, ok
testing with malloc debug settings:
#! /bin/bash
export MallocGuardEdges=1
export MallocScribble=1
export MallocStackLogg
export MallocCheckHeap
export MallocCheckHeap
export MallocCheckHeap
this gives an segfault on closing, but its the same on trunk.
plese check inline comment. Otherwise code LGTM.
Gun: get me mereg a private bracnh wit bunnybot and all,
or must his me moved to wideldans namespace, first.
Klaus Halfmann (klaus-halfmann) wrote : | # |
Gun: can we merge a private branch with bunnybot and all,
or must this be moved to wideldans namespace, first?
GunChleoc (gunchleoc) wrote : | # |
Thanks for cleaning up after me :)
Merging this with bunnybot is no problem.
I have added you to widelands-dev, so you we can work together on branches in the future. Just don't push directly to trunk :)
I think we can have a std::unique_ptr here for all the variables that you touched. It is clear who owns it, so we don't need shared_ptr, and raw pointers are something we want to get rid of.
The only raw pointers that are OK are for UI::Panel and its subclasses, because the pointers are managed well within UI::Panel and it would be a huge job to refactor that.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 2809. State: passed. Details: https:/
Appveyor build 2620. State: success. Details: https:/
Jukka Pakarinen (flegu) wrote : | # |
> Hellu Jukka (If got you first name correct).
You got it right.
> space, I can assit you how to do so.
Thanks for offering help!
Jukka Pakarinen (flegu) wrote : | # |
> I have added you to widelands-dev, so you we can work together on branches in
Thanks!
> the future. Just don't push directly to trunk :)
I keep that in mind!
> I think we can have a std::unique_ptr here for all the variables that you
> touched. It is clear who owns it, so we don't need shared_ptr, and raw
> pointers are something we want to get rid of.
Sounds good to me. I can try to change those to unique ones.
> The only raw pointers that are OK are for UI::Panel and its subclasses,
> because the pointers are managed well within UI::Panel and it would be a huge
> job to refactor that.
Good to know!
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 2813. State: failed. Details: https:/
Appveyor build 2624. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Code LGTM :)
You now need to add some headers to make Codecheck happy, then this can go in.
widelands/
widelands/
widelands/
The reason for this rule is that some compilers will barf if unique_ptr is used without this header.
Documentation on how to run codecheck yourself: https:/
Jukka Pakarinen (flegu) wrote : | # |
> Documentation on how to run codecheck yourself:
> https:/
Thanks for guiding me!
GunChleoc (gunchleoc) wrote : | # |
You're welcome! We're happy to have you on board and helping with those memory leaks :)
GunChleoc (gunchleoc) wrote : | # |
Now we're getting a compiler error:
Building CXX object src/wui/
/home/travis/
/home/travis/
return result;
^
/home/travis/
}
^
Jukka Pakarinen (flegu) wrote : | # |
That's weird! The code compiles fine with gcc 6.3.0. The code doesn't comple if I put "const" where it is missing. Maybe I just drop out the const.
SirVer (sirver) wrote : | # |
+1e6!!!! thank you for helping fighting these leaks!
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 2824. State: passed. Details: https:/
Appveyor build 2634. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
All ready now! :D
@bunnybot merge
Preview Diff
1 | === modified file 'src/ui_fsmenu/campaign_select.cc' | |||
2 | --- src/ui_fsmenu/campaign_select.cc 2017-03-05 17:55:29 +0000 | |||
3 | +++ src/ui_fsmenu/campaign_select.cc 2017-11-21 18:37:33 +0000 | |||
4 | @@ -424,10 +424,10 @@ | |||
5 | 424 | */ | 424 | */ |
6 | 425 | void FullscreenMenuCampaignMapSelect::fill_table() { | 425 | void FullscreenMenuCampaignMapSelect::fill_table() { |
7 | 426 | // read in the campaign config | 426 | // read in the campaign config |
9 | 427 | Profile* prof; | 427 | std::unique_ptr<Profile> prof; |
10 | 428 | std::string campsection; | 428 | std::string campsection; |
11 | 429 | if (is_tutorial_) { | 429 | if (is_tutorial_) { |
13 | 430 | prof = new Profile("campaigns/tutorials.conf", nullptr, "maps"); | 430 | prof.reset(new Profile("campaigns/tutorials.conf", nullptr, "maps")); |
14 | 431 | 431 | ||
15 | 432 | // Set subtitle of the page | 432 | // Set subtitle of the page |
16 | 433 | const std::string subtitle1 = _("Pick a tutorial from the list, then hit \"OK\"."); | 433 | const std::string subtitle1 = _("Pick a tutorial from the list, then hit \"OK\"."); |
17 | @@ -439,7 +439,7 @@ | |||
18 | 439 | campsection = "tutorials"; | 439 | campsection = "tutorials"; |
19 | 440 | 440 | ||
20 | 441 | } else { | 441 | } else { |
22 | 442 | prof = new Profile("campaigns/campaigns.conf", nullptr, "maps"); | 442 | prof.reset(new Profile("campaigns/campaigns.conf", nullptr, "maps")); |
23 | 443 | 443 | ||
24 | 444 | Section& global_s = prof->get_safe_section("global"); | 444 | Section& global_s = prof->get_safe_section("global"); |
25 | 445 | 445 | ||
26 | 446 | 446 | ||
27 | === modified file 'src/ui_fsmenu/loadgame.cc' | |||
28 | --- src/ui_fsmenu/loadgame.cc 2017-11-06 20:19:56 +0000 | |||
29 | +++ src/ui_fsmenu/loadgame.cc 2017-11-21 18:37:33 +0000 | |||
30 | @@ -19,6 +19,8 @@ | |||
31 | 19 | 19 | ||
32 | 20 | #include "ui_fsmenu/loadgame.h" | 20 | #include "ui_fsmenu/loadgame.h" |
33 | 21 | 21 | ||
34 | 22 | #include <memory> | ||
35 | 23 | |||
36 | 22 | #include "base/i18n.h" | 24 | #include "base/i18n.h" |
37 | 23 | #include "wui/gamedetails.h" | 25 | #include "wui/gamedetails.h" |
38 | 24 | 26 | ||
39 | @@ -114,7 +116,7 @@ | |||
40 | 114 | return; | 116 | return; |
41 | 115 | } | 117 | } |
42 | 116 | 118 | ||
44 | 117 | const SavegameData* gamedata = load_or_save_.entry_selected(); | 119 | std::unique_ptr<SavegameData> gamedata = load_or_save_.entry_selected(); |
45 | 118 | if (gamedata && gamedata->errormessage.empty()) { | 120 | if (gamedata && gamedata->errormessage.empty()) { |
46 | 119 | filename_ = gamedata->filename; | 121 | filename_ = gamedata->filename; |
47 | 120 | end_modal<FullscreenMenuBase::MenuTarget>(FullscreenMenuBase::MenuTarget::kOk); | 122 | end_modal<FullscreenMenuBase::MenuTarget>(FullscreenMenuBase::MenuTarget::kOk); |
48 | 121 | 123 | ||
49 | === modified file 'src/ui_fsmenu/options.cc' | |||
50 | --- src/ui_fsmenu/options.cc 2017-11-12 08:04:06 +0000 | |||
51 | +++ src/ui_fsmenu/options.cc 2017-11-21 18:37:33 +0000 | |||
52 | @@ -450,7 +450,7 @@ | |||
53 | 450 | 450 | ||
54 | 451 | std::string name = i18n::make_ligatures(table->get_string("name").c_str()); | 451 | std::string name = i18n::make_ligatures(table->get_string("name").c_str()); |
55 | 452 | const std::string sortname = table->get_string("sort_name"); | 452 | const std::string sortname = table->get_string("sort_name"); |
57 | 453 | LanguageEntry* entry = new LanguageEntry(localename, name); | 453 | std::unique_ptr<LanguageEntry> entry(new LanguageEntry(localename, name)); |
58 | 454 | entries.insert(std::make_pair(sortname, *entry)); | 454 | entries.insert(std::make_pair(sortname, *entry)); |
59 | 455 | language_entries_.insert(std::make_pair(localename, *entry)); | 455 | language_entries_.insert(std::make_pair(localename, *entry)); |
60 | 456 | 456 | ||
61 | 457 | 457 | ||
62 | === modified file 'src/wui/load_or_save_game.cc' | |||
63 | --- src/wui/load_or_save_game.cc 2017-11-06 20:19:56 +0000 | |||
64 | +++ src/wui/load_or_save_game.cc 2017-11-21 18:37:33 +0000 | |||
65 | @@ -20,6 +20,7 @@ | |||
66 | 20 | #include "wui/load_or_save_game.h" | 20 | #include "wui/load_or_save_game.h" |
67 | 21 | 21 | ||
68 | 22 | #include <ctime> | 22 | #include <ctime> |
69 | 23 | #include <memory> | ||
70 | 23 | 24 | ||
71 | 24 | #include <boost/algorithm/string.hpp> | 25 | #include <boost/algorithm/string.hpp> |
72 | 25 | #include <boost/format.hpp> | 26 | #include <boost/format.hpp> |
73 | @@ -168,8 +169,8 @@ | |||
74 | 168 | return r1.savetimestamp < r2.savetimestamp; | 169 | return r1.savetimestamp < r2.savetimestamp; |
75 | 169 | } | 170 | } |
76 | 170 | 171 | ||
79 | 171 | const SavegameData* LoadOrSaveGame::entry_selected() { | 172 | std::unique_ptr<SavegameData> LoadOrSaveGame::entry_selected() { |
80 | 172 | SavegameData* result = new SavegameData(); | 173 | std::unique_ptr<SavegameData> result(new SavegameData()); |
81 | 173 | size_t selections = table_.selections().size(); | 174 | size_t selections = table_.selections().size(); |
82 | 174 | if (selections == 1) { | 175 | if (selections == 1) { |
83 | 175 | delete_->set_tooltip( | 176 | delete_->set_tooltip( |
84 | @@ -178,7 +179,7 @@ | |||
85 | 178 | _("Delete this replay") : | 179 | _("Delete this replay") : |
86 | 179 | /** TRANSLATORS: Tooltip for the delete button. The user has selected 1 file */ | 180 | /** TRANSLATORS: Tooltip for the delete button. The user has selected 1 file */ |
87 | 180 | _("Delete this game")); | 181 | _("Delete this game")); |
89 | 181 | result = &games_data_[table_.get_selected()]; | 182 | result.reset(new SavegameData(games_data_[table_.get_selected()])); |
90 | 182 | } else if (selections > 1) { | 183 | } else if (selections > 1) { |
91 | 183 | delete_->set_tooltip( | 184 | delete_->set_tooltip( |
92 | 184 | filetype_ == FileType::kReplay ? | 185 | filetype_ == FileType::kReplay ? |
93 | 185 | 186 | ||
94 | === modified file 'src/wui/load_or_save_game.h' | |||
95 | --- src/wui/load_or_save_game.h 2017-08-12 08:03:19 +0000 | |||
96 | +++ src/wui/load_or_save_game.h 2017-11-21 18:37:33 +0000 | |||
97 | @@ -20,6 +20,8 @@ | |||
98 | 20 | #ifndef WL_WUI_LOAD_OR_SAVE_GAME_H | 20 | #ifndef WL_WUI_LOAD_OR_SAVE_GAME_H |
99 | 21 | #define WL_WUI_LOAD_OR_SAVE_GAME_H | 21 | #define WL_WUI_LOAD_OR_SAVE_GAME_H |
100 | 22 | 22 | ||
101 | 23 | #include <memory> | ||
102 | 24 | |||
103 | 23 | #include "logic/game.h" | 25 | #include "logic/game.h" |
104 | 24 | #include "ui_basic/box.h" | 26 | #include "ui_basic/box.h" |
105 | 25 | #include "ui_basic/panel.h" | 27 | #include "ui_basic/panel.h" |
106 | @@ -43,7 +45,7 @@ | |||
107 | 43 | bool localize_autosave); | 45 | bool localize_autosave); |
108 | 44 | 46 | ||
109 | 45 | /// Update gamedetails and tooltips and return information about the current selection | 47 | /// Update gamedetails and tooltips and return information about the current selection |
111 | 46 | const SavegameData* entry_selected(); | 48 | std::unique_ptr<SavegameData> entry_selected(); |
112 | 47 | 49 | ||
113 | 48 | /// Whether the table has a selection | 50 | /// Whether the table has a selection |
114 | 49 | bool has_selection() const; | 51 | bool has_selection() const; |
Hellu Jukka (If got you first name correct).
Thanks for finding/fixing those Issues. We actually have
a long standing problem with Memory corruption when playing
for a longer time e.g. #1730204 so anyonw with knowledge and
tooling is welcome.
If you are a registered widelands developer,
you may consdier putting such branches into the public
space, I can assit you how to do so.
You can find me in the lobby and on widelands.org as Hasi50.
I am devloping mostly on OSX with clang / macports. But I can
switch to Win10 or Ubuntu, if needed.
Now let me check that code