Bug 479929 - Return value of esd_open_sound not checked correctly. r+sr=roc
authorMatthew Gregan <kinetik@flim.org>
Tue, 24 Feb 2009 18:06:42 +1300
changeset 25535 5ac18226837e06a06690de4fc877e521a3a1aebd
parent 25534 9bdfe330b2aa93b04952a8b584793b6afbe555dc
child 25536 59d848818fd8d1f1e2b04d6a9d7aa913194f8a49
push id5597
push usermgregan@mozilla.com
push dateThu, 26 Feb 2009 07:34:15 +0000
treeherdermozilla-central@98f8aef2dce4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs479929
milestone1.9.2a1pre
Bug 479929 - Return value of esd_open_sound not checked correctly. r+sr=roc
widget/src/gtk2/nsSound.cpp
--- a/widget/src/gtk2/nsSound.cpp
+++ b/widget/src/gtk2/nsSound.cpp
@@ -126,18 +126,17 @@ NS_IMPL_ISUPPORTS2(nsSound, nsISound, ns
 ////////////////////////////////////////////////////////////////////////
 nsSound::nsSound()
 {
     mInited = PR_FALSE;
 }
 
 nsSound::~nsSound()
 {
-    /* see above comment */
-    if (esdref != -1) {
+    if (esdref >= 0) {
         EsdCloseType EsdClose = (EsdCloseType) PR_FindFunctionSymbol(elib, "esd_close");
         if (EsdClose)
             (*EsdClose)(esdref);
         esdref = -1;
     }
 }
 
 NS_IMETHODIMP
@@ -146,29 +145,26 @@ nsSound::Init()
     // This function is designed so that no library is compulsory, and
     // one library missing doesn't cause the other(s) to not be used.
     if (mInited) 
         return NS_OK;
 
     mInited = PR_TRUE;
 
     if (!elib) {
-        /* we don't need to do esd_open_sound if we are only going to play files
-           but we will if we want to do things like streams, etc */
-        EsdOpenSoundType EsdOpenSound;
-
         elib = PR_LoadLibrary("libesd.so.0");
         if (elib) {
-            EsdOpenSound = (EsdOpenSoundType) PR_FindFunctionSymbol(elib, "esd_open_sound");
+            EsdOpenSoundType EsdOpenSound =
+                (EsdOpenSoundType) PR_FindFunctionSymbol(elib, "esd_open_sound");
             if (!EsdOpenSound) {
                 PR_UnloadLibrary(elib);
                 elib = nsnull;
             } else {
                 esdref = (*EsdOpenSound)("localhost");
-                if (!esdref) {
+                if (esdref < 0) {
                     PR_UnloadLibrary(elib);
                     elib = nsnull;
                 }
             }
         }
     }
 
     if (!libasound) {
@@ -375,17 +371,17 @@ NS_IMETHODIMP nsSound::OnStreamComplete(
         buf = new PRUint8[audio_len];
         if (!buf)
             return NS_ERROR_OUT_OF_MEMORY;
         for (PRUint32 j = 0; j + 2 < audio_len; j += 2) {
             buf[j]     = audio[j + 1];
             buf[j + 1] = audio[j];
         }
 
-	audio = buf;
+        audio = buf;
     }
 #endif
 
     fd = (*EsdPlayStream)(mask, samples_per_sec, NULL, "mozillaSound"); 
   
     if (fd < 0) {
       int *esd_audio_format = (int *) PR_FindSymbol(elib, "esd_audio_format");
       int *esd_audio_rate = (int *) PR_FindSymbol(elib, "esd_audio_rate");