SDL_mixer/mikmod bugs with different channelcount in mod files

Hi,

I just found some bugs in the mikmod code inside SDL_mixer (version
1.2.5). The problems occur when you load several modules with different
channel numbers at once into memory.

I attached sample code that demonstrates the crashs on this mail. Just
place a file with 6 channels as 1.mod and a file with 4 channels as 2.mod
into the directory of the sample app. (I was using these files BTW:
http://cvs.sourceforge.net/viewcvs.py/checkout/super-tux/supertux/data/music/theme.mod?rev=1.2
http://cvs.sourceforge.net/viewcvs.py/checkout/super-tux/supertux/data/music/SALCON.MOD?rev=1.2
)

I looked a bit at the sourcecode and the problem seems to be related to
the Player_LoadGeneric_internal function which is calling
MikMod_SetNumVoices_internal, which then sets the global variable
md_numchn. When you then play/free the mods the number inside md_numchn
might be too big and the player is using/freeing after the end of the
voice array in the MODULE struct. I’m not sure how to fix this problem
nicely though.

Greetings,
Matze
-------------- next part --------------
#include <SDL.h>
#include <SDL_mixer.h>

int main()
{
SDL_Init(SDL_INIT_AUDIO);

Mix_OpenAudio(44100, AUDIO_S16, 2, 2048);

printf("load1.\n");
Mix_Music* music1 = Mix_LoadMUS("1.mod");
printf("load2.\n");
Mix_Music* music2 = Mix_LoadMUS("2.mod");
printf("load3.\n");
Mix_Music* music3 = Mix_LoadMUS("1.mod");

printf("pl1.\n");
Mix_PlayMusic(music1, -1);
SDL_Delay(500);

printf("pl2.\n");
Mix_PlayMusic(music2, -1);
SDL_Delay(500);

printf("pl3.\n");
Mix_PlayMusic(music3, -1);
SDL_Delay(500);

printf("pl2.\n");
Mix_PlayMusic(music2, -1);
SDL_Delay(500);               

printf("pl1.\n");
Mix_PlayMusic(music1, -1);
SDL_Delay(500);

printf("free1.\n");
Mix_FreeMusic(music1);
printf("free2.\n");
Mix_FreeMusic(music2);
printf("free3.\n");
Mix_FreeMusic(music3);

SDL_Quit();

}