summaryrefslogtreecommitdiff
path: root/src/resources/sdlmusic.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-15 01:12:30 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-15 01:12:30 +0300
commit54d665ca2ff9244ef4b5a6dc48424d4a3364a40c (patch)
tree5e2a0d0acad140d0842d4ee169131049fd5b1af7 /src/resources/sdlmusic.cpp
parent4206ffda4d2acd238c8f0093345af0431cf8a863 (diff)
downloadplus-54d665ca2ff9244ef4b5a6dc48424d4a3364a40c.tar.gz
plus-54d665ca2ff9244ef4b5a6dc48424d4a3364a40c.tar.bz2
plus-54d665ca2ff9244ef4b5a6dc48424d4a3364a40c.tar.xz
plus-54d665ca2ff9244ef4b5a6dc48424d4a3364a40c.zip
fix music RWops memory leak.
Diffstat (limited to 'src/resources/sdlmusic.cpp')
-rw-r--r--src/resources/sdlmusic.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/resources/sdlmusic.cpp b/src/resources/sdlmusic.cpp
index fb31c0562..03c6922d6 100644
--- a/src/resources/sdlmusic.cpp
+++ b/src/resources/sdlmusic.cpp
@@ -26,28 +26,37 @@
#include "debug.h"
-SDLMusic::SDLMusic(Mix_Music *const music) :
+SDLMusic::SDLMusic(Mix_Music *const music, SDL_RWops *const rw) :
Resource(),
- mMusic(music)
+ mMusic(music),
+ mRw(rw)
{
}
SDLMusic::~SDLMusic()
{
Mix_FreeMusic(mMusic);
+#ifndef USE_SDL2
+ if (mRw)
+ {
+ SDL_RWclose(mRw);
+ mRw = nullptr;
+ }
+#endif
}
Resource *SDLMusic::load(SDL_RWops *const rw)
{
#ifdef USE_SDL2
if (Mix_Music *const music = Mix_LoadMUSType_RW(rw, MUS_OGG, 1))
+ {
+ return new SDLMusic(music, nullptr);
#else
- // +++ here probably mem leak
// Mix_LoadMUSType_RW was added without version changed in SDL1.2 :(
if (Mix_Music *const music = Mix_LoadMUS_RW(rw))
-#endif
{
- return new SDLMusic(music);
+ return new SDLMusic(music, rw);
+#endif
}
else
{