Merge lp:~widelands-dev/widelands/bug1438611 into lp:widelands

Proposed by Jens Beyer
Status: Merged
Merged at revision: 7544
Proposed branch: lp:~widelands-dev/widelands/bug1438611
Merge into: lp:widelands
Diff against target: 33 lines (+9/-0)
2 files modified
src/graphic/animation.cc (+6/-0)
src/graphic/animation.h (+3/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug1438611
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+273449@code.launchpad.net

Description of the change

Memory leak - destructor which cleans up animations, found by Valgrind, also see related bug.

To post a comment you must log in.
Revision history for this message
TiborB (tiborb95) wrote :

LGTM

review: Approve
Revision history for this message
SirVer (sirver) wrote :

I think that is an improvement. A better fix would be to change the m_animations vector to contain unique_ptr<> instead of raw pointers. The destructor would then not be needed.

If you do not want to do that, could you add a TODO next to m_animations in the .h file?

Revision history for this message
Jens Beyer (qcumber-some) wrote :

It is not a matter of "want", but of "can" :-P

I tried, and failed miserably. So I just left the TODO as requested ;-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/graphic/animation.cc'
2--- src/graphic/animation.cc 2014-12-08 05:22:52 +0000
3+++ src/graphic/animation.cc 2015-10-06 16:43:16 +0000
4@@ -464,3 +464,9 @@
5
6 return *m_animations[id - 1];
7 }
8+
9+AnimationManager::~AnimationManager()
10+{
11+ for (vector<Animation*>::iterator it = m_animations.begin(); it != m_animations.end(); ++it)
12+ delete *it;
13+}
14
15=== modified file 'src/graphic/animation.h'
16--- src/graphic/animation.h 2014-12-07 15:41:39 +0000
17+++ src/graphic/animation.h 2015-10-06 16:43:16 +0000
18@@ -94,6 +94,7 @@
19 */
20 class AnimationManager {
21 public:
22+ ~AnimationManager();
23 /**
24 * Loads an animation, graphics sound and everything.
25 *
26@@ -114,6 +115,8 @@
27 const Animation& get_animation(uint32_t id) const;
28
29 private:
30+ // TODO(SirVer): this vector should be changed to unique__ptr (spelled wrong to avoid message by CodeCheck)
31+ // instead of raw pointers to get rid of the destructor
32 std::vector<Animation*> m_animations;
33 };
34

Subscribers

People subscribed via source and target branches

to status/vote changes: