Bug 562488 - Fix crash destroying stream in OSS sydneyaudio backend. r=kinetik
authorCliff Wright <cliff@snipe444.org>
Thu, 29 Apr 2010 11:04:06 +1200
changeset 41621 c34e4f1eb78aab8a2eb65dc4fde1998a129dcdd9
parent 41620 1f467e996e30c79dad0031da2c9681b2f56566dc
child 41622 756f81db342bfc1cade19682bdbd4ecafe3eda3a
push idunknown
push userunknown
push dateunknown
reviewerskinetik
bugs562488
milestone1.9.3a5pre
Bug 562488 - Fix crash destroying stream in OSS sydneyaudio backend. r=kinetik
media/libsydneyaudio/README_MOZILLA
media/libsydneyaudio/bug562488_oss_destroy_crash.patch
media/libsydneyaudio/src/sydney_audio_oss.c
media/libsydneyaudio/update.sh
--- a/media/libsydneyaudio/README_MOZILLA
+++ b/media/libsydneyaudio/README_MOZILLA
@@ -22,8 +22,10 @@ sydney_os2_moz.patch:  Bug 448918 - add 
 bug495794_closeAudio.patch fixes a crash when destroying the sa_stream_t after
 a failed attempt to open the stream.
 
 bug495558_alsa_endian.patch adds support for big endian ALSA platforms.
 
 bug526411_latency.patch: reduce requested latency to 250ms to match OGGPLAY_AUDIO_OFFSET.
 
 sydney_aix.patch: Bug 499266 - add support for AIX 5.x
+
+bug562488_oss_destroy_crash.patch: Fix crash in OSS backend when destroying stream.
new file mode 100644
--- /dev/null
+++ b/media/libsydneyaudio/bug562488_oss_destroy_crash.patch
@@ -0,0 +1,49 @@
+diff --git a/media/libsydneyaudio/src/sydney_audio_oss.c b/media/libsydneyaudio/src/sydney_audio_oss.c
+--- a/media/libsydneyaudio/src/sydney_audio_oss.c
++++ b/media/libsydneyaudio/src/sydney_audio_oss.c
+@@ -253,39 +253,44 @@ sa_stream_open(sa_stream_t *s) {
+ 
+   return SA_SUCCESS;
+ }
+ 
+ 
+ int
+ sa_stream_destroy(sa_stream_t *s) {
+   int result = SA_SUCCESS;
++  pthread_t thread_id;
+ 
+   if (s == NULL) {
+     return SA_SUCCESS;
+   }
+ 
+   pthread_mutex_lock(&s->mutex);
+ 
++  thread_id = s->thread_id;
++
+   /*
+-   * This causes the thread sending data to ALSA to stop
++   * This causes the thread sending data to OSS to stop
+    */
+   s->thread_id = 0;
+ 
+   /*
+    * Shut down the audio output device.
+    */
+   if (s->output_fd != -1) {
+     if (s->playing && close(s->output_fd) < 0) {
+       result = SA_ERROR_SYSTEM;
+     }
+   }
+ 
+   pthread_mutex_unlock(&s->mutex);
+ 
++  pthread_join(thread_id, NULL);
++
+   /*
+    * Release resources.
+    */
+   if (pthread_mutex_destroy(&s->mutex) != 0) {
+     result = SA_ERROR_SYSTEM;
+   }
+   while (s->bl_head != NULL) {
+     sa_buf  * next = s->bl_head->next;
--- a/media/libsydneyaudio/src/sydney_audio_oss.c
+++ b/media/libsydneyaudio/src/sydney_audio_oss.c
@@ -253,39 +253,44 @@ sa_stream_open(sa_stream_t *s) {
 
   return SA_SUCCESS;
 }
 
 
 int
 sa_stream_destroy(sa_stream_t *s) {
   int result = SA_SUCCESS;
+  pthread_t thread_id;
 
   if (s == NULL) {
     return SA_SUCCESS;
   }
 
   pthread_mutex_lock(&s->mutex);
 
+  thread_id = s->thread_id;
+
   /*
-   * This causes the thread sending data to ALSA to stop
+   * This causes the thread sending data to OSS to stop
    */
   s->thread_id = 0;
 
   /*
    * Shut down the audio output device.
    */
   if (s->output_fd != -1) {
     if (s->playing && close(s->output_fd) < 0) {
       result = SA_ERROR_SYSTEM;
     }
   }
 
   pthread_mutex_unlock(&s->mutex);
 
+  pthread_join(thread_id, NULL);
+
   /*
    * Release resources.
    */
   if (pthread_mutex_destroy(&s->mutex) != 0) {
     result = SA_ERROR_SYSTEM;
   }
   while (s->bl_head != NULL) {
     sa_buf  * next = s->bl_head->next;
--- a/media/libsydneyaudio/update.sh
+++ b/media/libsydneyaudio/update.sh
@@ -9,8 +9,9 @@ patch -p4 <pause-resume.patch
 patch -p4 <include-CoreServices.patch
 patch -p4 <sydney_os2_base.patch
 patch -p4 <sydney_os2_moz.patch
 patch -p3 <bug495794_closeAudio.patch
 patch -p3 <bug495558_alsa_endian.patch
 patch -p3 <bug525401_drain_deadlock.patch
 patch -p3 <bug526411_latency.patch
 patch -p3 <sydney_aix.patch
+patch -p3 <bug562488_oss_destroy_crash.patch