]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
ao_write: Avoid segfault on exit.
authorAndre Noll <maan@systemlinux.org>
Mon, 3 Feb 2014 20:06:00 +0000 (21:06 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 6 Apr 2014 06:53:26 +0000 (08:53 +0200)
If para_audiod is terminated by a signal it calls the ->close() method
of each active writer. In this method the ao writer calls ao_close()
and frees all resources but leaves the play thread active. So the
thread continues to run, prints

ao_alsa ERROR: write error: File descriptor in bad state

and probably crashes afterwards due to accessing freed memory. Fix this
by cancelling the thread in ->close() if it exists. Ironically enough,
this re-introduces a call to pthread_join(), but it's OK here since
we the cancelled thread should exit immediately (so we don't block),
and we are about to exit anyway.

ao_write.c

index a2e86ed258c5857ff10014ea99d1335009e2a97b..12ab77fe8dc33c1b5be189eff6bd4621cb4305a6 100644 (file)
@@ -39,6 +39,10 @@ static void aow_close(struct writer_node *wn)
 
        if (!pawd)
                return;
+       if (pawd->thread_btrn) {
+               pthread_cancel(pawd->thread);
+               pthread_join(pawd->thread, NULL);
+       }
        ao_close(pawd->dev);
        free(pawd);
        wn->private_data = NULL;