SDL_RWclose(music_rw) + Mix_FreeMusic(music) = double-free

I’m streaming music via RWops using Mix_LoadMUS_RW which means leaving the
file open until the music is stopped. When it comes time to stop the music
I call both SDL_RWclose(music_rw) and Mix_FreeMusic(music) which results in
a double-free error. My question is: which of the two commands is
redundant?

I can’t find the code for Mix_LoadMUS_RW but I’m guessing it keeps a
pointer to music_rw with is used to free the structure when
Mix_FreeMusic(music) is called. In this case it’s SDL_RWclose that needs to
be removed.

William

Correct. Mix_FreeMusic() will automatically delete the RWops if you
created the Mix_Music with Mix_LoadMUS_RW(). If you use
Mix_LoadMUSType_RW() though, you can specify whether the RWops should be
automatically freed or not.On 05/06/12 01:01, William Dyce wrote:

I’m streaming music via RWops using Mix_LoadMUS_RW which means leaving
the file open until the music is stopped. When it comes time to stop the
music I call both SDL_RWclose(music_rw) and Mix_FreeMusic(music) which
results in a double-free error. My question is: which of the two
commands is redundant?

I can’t find the code for Mix_LoadMUS_RW but I’m guessing it keeps a
pointer to music_rw with is used to free the structure when
Mix_FreeMusic(music) is called. In this case it’s SDL_RWclose that needs
to be removed.