From c19af3525eff22cb0f9947b7dfea67d3f6eec8a9 Mon Sep 17 00:00:00 2001
From: ehofman <ehofman>
Date: Sun, 21 Nov 2004 17:05:42 +0000
Subject: [PATCH] Melchior FRANZ:

At last I've found the reason why fgfs crashed routinely for me. When I still
used KDE's artsdsp (preloads lib with OSS replacement functions) I saw
this crash only occasionally. After letting OpenAl communicate with artsd
directly (by means of ~/.openalrc setting), I got the crash always when
I left fgfs.

This bug may also have crashed fgfs when running with sound daemons other than
aRts.
---
 simgear/sound/soundmgr_openal.cxx | 5 ++---
 simgear/sound/xmlsound.cxx        | 7 ++-----
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx
index 0785edb5..b525b31f 100644
--- a/simgear/sound/soundmgr_openal.cxx
+++ b/simgear/sound/soundmgr_openal.cxx
@@ -69,7 +69,8 @@ SGSoundMgr::SGSoundMgr() {
 
     // initialize OpenAL
     alutInit( 0, NULL );
-    alGetError();
+    atexit(alutExit);
+
     if ( alGetError() == AL_NO_ERROR) {
         working = true;
     } else {
@@ -119,8 +120,6 @@ SGSoundMgr::~SGSoundMgr() {
 	SGSoundSample *sample = sample_current->second;
 	delete sample;
     }
-
-    alutExit();
 }
 
 
diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx
index 48a2d0ee..fbb4504a 100644
--- a/simgear/sound/xmlsound.cxx
+++ b/simgear/sound/xmlsound.cxx
@@ -80,11 +80,8 @@ SGXmlSound::~SGXmlSound()
 {
     _sample->stop();
 
-    if (_property)
-        delete _property;
-
-    if (_condition)
-        delete _condition;
+    delete _property;
+    delete _condition;
 
     _volume.clear();
     _pitch.clear();
-- 
2.39.5