media/libsydneyaudio/bug562488_oss_destroy_crash.patch
author Cliff Wright <cliff@snipe444.org>
Thu, 29 Apr 2010 11:04:06 +1200
changeset 41621 c34e4f1eb78aab8a2eb65dc4fde1998a129dcdd9
permissions -rw-r--r--
Bug 562488 - Fix crash destroying stream in OSS sydneyaudio backend. r=kinetik

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;