Date: Fri, 22 Jul 2005 23:12:49 +1000
authorSam Lantinga <slouken@libsdl.org>
Sun, 21 Aug 2005 20:54:52 +0000
changeset 27600ff1db6f904
parent 275 0af5279efb57
child 277 7d1be40dca4a
Date: Fri, 22 Jul 2005 23:12:49 +1000
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 :(
mikmod/mikmod.h
music.c
     1.1 --- a/mikmod/mikmod.h	Sat Jul 16 16:52:28 2005 +0000
     1.2 +++ b/mikmod/mikmod.h	Sun Aug 21 20:54:52 2005 +0000
     1.3 @@ -650,6 +650,8 @@
     1.4  MIKMODAPI extern struct MDRIVER drv_stdout; /* output to stdout */
     1.5  MIKMODAPI extern struct MDRIVER drv_wav;    /* RIFF WAVE file disk writer [music.wav] */
     1.6  
     1.7 +MIKMODAPI extern struct MDRIVER drv_sdl;    /* SDL_mixer driver */
     1.8 +
     1.9  MIKMODAPI extern struct MDRIVER drv_ultra;  /* Linux Ultrasound driver */
    1.10  
    1.11  MIKMODAPI extern struct MDRIVER drv_AF;     /* Dec Alpha AudioFile */
     2.1 --- a/music.c	Sat Jul 16 16:52:28 2005 +0000
     2.2 +++ b/music.c	Sun Aug 21 20:54:52 2005 +0000
     2.3 @@ -327,6 +327,9 @@
     2.4  int open_music(SDL_AudioSpec *mixer)
     2.5  {
     2.6  	int music_error;
     2.7 +#ifdef LIBMIKMOD_MUSIC
     2.8 +	CHAR *list;
     2.9 +#endif
    2.10  
    2.11  	music_error = 0;
    2.12  #ifdef WAV_MUSIC
    2.13 @@ -388,14 +391,17 @@
    2.14  	md_mode |= DMODE_HQMIXER|DMODE_SOFT_MUSIC|DMODE_SURROUND;
    2.15  #endif
    2.16  #ifdef LIBMIKMOD_MUSIC
    2.17 -	if(!MikMod_InfoDriver())
    2.18 -          MikMod_RegisterDriver(&drv_nos);
    2.19 -#else
    2.20 -	MikMod_RegisterAllDrivers();
    2.21 +	list = MikMod_InfoDriver();
    2.22 +	if ( list )
    2.23 +	  free(list);
    2.24 +	else
    2.25  #endif
    2.26 -
    2.27 +	MikMod_RegisterDriver(&drv_nos);
    2.28  #ifdef LIBMIKMOD_MUSIC
    2.29 -	if(!MikMod_InfoLoader())
    2.30 +	list = MikMod_InfoLoader();
    2.31 +	if ( list )
    2.32 +	  free(list);
    2.33 +	else
    2.34  #endif
    2.35  	MikMod_RegisterAllLoaders();
    2.36  	if ( MikMod_Init() ) {