Skip to content

Commit

Permalink
Date: Fri, 22 Jul 2005 23:12:49 +1000
Browse files Browse the repository at this point in the history
From: Ian Munsie
Subject: URGENT: SDL_mixer-1.2.6 bug fix (or two)

bug info: When SDL_mixer attempted to initialise libmikmod, it used
all drivers embedded in the libmikmod. Problem was, that the sound
card drivers were already in use by SDL, so libmikmod would hang
waiting for them to become free on many systems. As SDL_mixer uses a
hook to transfer the final stream from libmikmod into SDL_mixer's
mixer, there is no reason that libmikmod should be using a card driver
at all, the nosound driver still does all the internal processing, and
will still call the hook fine.

bug info: Please read the libmikmod documentation more carefully, it
clearly states that MikMod_InfoDriver() and MikMod_InfoLoader() uses
malloc to dynamically allocate a char array to hold a list of
drivers/loaders (as opposed to simply returning a pointer to a static
char array, in which case your code would be fine), and that you must
free() it after use. It should be fine to remove these statements
completely (unless someone compiled libmikmod with no embeded drivers
or loaders :S), but if you want to keep them, PLEASE store the return
value of these functions in a temporary variable so you can free()
them afterwards.
Your code never frees that string, and as a result has a memory leak :(
  • Loading branch information
slouken committed Aug 21, 2005
1 parent 1a79445 commit 9701455
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions mikmod/mikmod.h
Expand Up @@ -650,6 +650,8 @@ MIKMODAPI extern struct MDRIVER drv_raw; /* raw file disk writer [music.raw]
MIKMODAPI extern struct MDRIVER drv_stdout; /* output to stdout */
MIKMODAPI extern struct MDRIVER drv_wav; /* RIFF WAVE file disk writer [music.wav] */

MIKMODAPI extern struct MDRIVER drv_sdl; /* SDL_mixer driver */

MIKMODAPI extern struct MDRIVER drv_ultra; /* Linux Ultrasound driver */

MIKMODAPI extern struct MDRIVER drv_AF; /* Dec Alpha AudioFile */
Expand Down
18 changes: 12 additions & 6 deletions music.c
Expand Up @@ -327,6 +327,9 @@ void music_mixer(void *udata, Uint8 *stream, int len)
int open_music(SDL_AudioSpec *mixer)
{
int music_error;
#ifdef LIBMIKMOD_MUSIC
CHAR *list;
#endif

music_error = 0;
#ifdef WAV_MUSIC
Expand Down Expand Up @@ -388,14 +391,17 @@ int open_music(SDL_AudioSpec *mixer)
md_mode |= DMODE_HQMIXER|DMODE_SOFT_MUSIC|DMODE_SURROUND;
#endif
#ifdef LIBMIKMOD_MUSIC
if(!MikMod_InfoDriver())
MikMod_RegisterDriver(&drv_nos);
#else
MikMod_RegisterAllDrivers();
list = MikMod_InfoDriver();
if ( list )
free(list);
else
#endif

MikMod_RegisterDriver(&drv_nos);
#ifdef LIBMIKMOD_MUSIC
if(!MikMod_InfoLoader())
list = MikMod_InfoLoader();
if ( list )
free(list);
else
#endif
MikMod_RegisterAllLoaders();
if ( MikMod_Init() ) {
Expand Down

0 comments on commit 9701455

Please sign in to comment.