Malloc problems with SDL_mixer under OS X [2]

I finally got the time to track down the line of code which causes the
segfault when switching MIDI songs. It’s "CloseComponent(gTunePlayer)"
in native_midi_freesong() in native_midi_mac.c. This is a QuickTime
function call, so this is as deep as I can debug. I have no idea why
this causes segmentation faults, neither why it seems to happen only on
my machine…


Lex wrote:> I have a weird problem with SDL_mixer. I’m working on a port of Rise Of

The Triad for Mac OS X, and the game currently crashes often when
switching MIDI songs. The crash occurs when calling Mix_FreeMusic. It
only occurs after playing a few songs. After about 3 to 5 songs, malloc
errors start to show up, and after a few more songs, a segfault occurs.
I wrote a very basic program which just loads and plays songs in the
same way, and it has exactly the same behavior. It’s at the bottom of
this post. Some songs from the game can be found at

If you want to download the current version of the ROTT source code, you
can get it at
Or you can get the compiled binary at
You’ll also need the ROTT game files, which can be downloaded at

The weird thing is that the guys working on SDL_mixer can’t reproduce
this problem, so it might be related to ‘external factors’. Therefore it
would be interesting if as many OS X users here could try either the
simple program below or the game itself, and report the results together
with their versions of OS X and QuickTime. To switch songs in the game
easily, type “dipstick” and “maestro” after starting a game, which will
give you a jukebox.


----------- Example C program follows: ------------

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include “SDL.h”
#include “SDL_mixer.h”

#ifdef main

undef main


int main (int argc, const char * argv[]) {
int i, numChannels;
char fName[256];
Mix_Music *music_musicchunk = NULL;

if (Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 256) < 0)
numChannels = Mix_AllocateChannels(8);
if (numChannels != 8)

for(i = 1; i < 10; i++) {
    printf("Playing song %d\n",i);
    music_musicchunk = Mix_LoadMUS(fName);
    Mix_PlayMusic(music_musicchunk, 0);
    if ( (Mix_PlayingMusic()) || (Mix_PausedMusic()) )
    Mix_FreeMusic(music_musicchunk); // This is where it crashes!
    music_musicchunk = NULL;
printf("Played all songs without crashing!\n");

return 0;