widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #01056
[Merge] lp:~csirkeee/widelands/bug1150517_3 into lp:widelands
Kiscsirke has proposed merging lp:~csirkeee/widelands/bug1150517_3 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~csirkeee/widelands/bug1150517_3/+merge/154198
A fix for bug 1150517 that makes freeing the data conditional on the version of SDL_Mixer.
--
https://code.launchpad.net/~csirkeee/widelands/bug1150517_3/+merge/154198
Your team Widelands Developers is requested to review the proposed merge of lp:~csirkeee/widelands/bug1150517_3 into lp:widelands.
=== modified file 'src/sound/songset.cc'
--- src/sound/songset.cc 2013-02-25 10:41:34 +0000
+++ src/sound/songset.cc 2013-03-19 20:50:32 +0000
@@ -25,6 +25,21 @@
#include "log.h"
+#include <utility>
+
+namespace {
+ // The behaviour of whether SDL_Mixer frees the RW it uses was changed with SDL_Mixer version 1.2.12, this
+ // check is so that we don't have a memory leak in the new version.
+ // TODO: Once we can demand that everyone use SDL_Mixer version >= 1.2.12, this function should be removed,
+ // and all usages replaced supposing it's true.
+ bool have_to_free_rw() {
+ return
+ std::make_pair
+ (SDL_MIXER_MAJOR_VERSION, std::make_pair(SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL)) >=
+ std::make_pair(1, std::make_pair(2, 12));
+ }
+}
+
/// Prepare infrastructure for reading song files from disk
Songset::Songset() : m_m(0), m_rwops(0) {}
@@ -37,7 +52,8 @@
Mix_FreeMusic(m_m);
if (m_rwops) {
- SDL_FreeRW(m_rwops);
+ if (have_to_free_rw())
+ SDL_FreeRW(m_rwops);
m_fr.Close();
}
}
@@ -82,7 +98,8 @@
}
if (m_rwops) {
- SDL_FreeRW(m_rwops);
+ if (have_to_free_rw())
+ SDL_FreeRW(m_rwops);
m_rwops = 0;
m_fr.Close();
}