Crashes when using aRts on Linux

Hi folks,

We had a problem with my app using SDL. It always crashed after SDL_OpenAudio(),
if the artsd was running on a Linux machine with KDE. After some investigation
(and searching for differences in other apps using arts) we found out, that the
problem resulted from loading, calling arts_init(), calling arts_free() and
unloading the aRts-Library in …/src/audio/arts/SDL_artsaudio.c twice: first in
"static int Audio_Available()", the second time in “static SDL_AudioDevice
*Audio_CreateDevice(int devindex)”.

This is how Audio_Available(void) in Version 1.2.7 looks like:

-------- snip (…/src/audio/arts/SDL_artsaudio.c) -------

/* Audio driver bootstrap functions */

static int Audio_Available(void)
{
int available = 1;

if ( LoadARTSLibrary() < 0 ) {
	return available;
}
if ( SDL_NAME(arts_init)() == 0 ) {
	available = 1;
	SDL_NAME(arts_free)();
}
UnloadARTSLibrary();

return available;

}

-------- snip -------

aRts seems to have a complex reference counting for its objects and somehow some
of objects remain in the memory after arts_init() and arts_free() with no stream
to play between them, which results in problems with pointers pointing to
invalid memory areas.

The following code fixes the problems, aRts cleans up the memory correctly with
it and the crashes are gone:

-------- snip(…/src/audio/arts/SDL_artsaudio.c) -------

/* Audio driver bootstrap functions */

static int Audio_Available(void)
{
int available = 0;
arts_stream_t stream2;

if ( LoadARTSLibrary() < 0 ) {
	return available;
}

if ( SDL_NAME(arts_init)() == 0 ) {
	available = 1;
	// play a stream
    	stream2=SDL_NAME(arts_play_stream)(44100, 16, 2, "SDL");
	SDL_NAME(arts_write)(stream2, "", 0);
	SDL_NAME(arts_close_stream)(stream2);
	SDL_NAME(arts_free)();
}

UnloadARTSLibrary();
return available;

}

-------- snip -------

I dont know, whether aRts is meant to be used only that way ( arts_init(), play
a stream, arts_free() ), or if the memory problems are a bug in aRts because no
one thought of using it otherwise. But I suggest adding this code to SDL to
avoid further problems anyway.

Keep up the good work, folks!

Yves

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4578 bytes
Desc: S/MIME Cryptographic Signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040705/0c66ec84/attachment.bin

We had a problem with my app using SDL. It always crashed after SDL_OpenAudio(),
if the artsd was running on a Linux machine with KDE. After some investigation
(and searching for differences in other apps using arts) we found out, that the
problem resulted from loading, calling arts_init(), calling arts_free() and
unloading the aRts-Library in …/src/audio/arts/SDL_artsaudio.c twice: first in
"static int Audio_Available()", the second time in “static SDL_AudioDevice
*Audio_CreateDevice(int devindex)”.

Thanks, your patch is in CVS. Can you check it out?

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment