From 5323dab36cfea7ee18f6ade7e38f1218cd7a9ea5 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 3 Feb 2014 21:06:00 +0100 Subject: [PATCH] ao_write: Avoid segfault on exit. 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ao_write.c b/ao_write.c index a2e86ed2..12ab77fe 100644 --- a/ao_write.c +++ b/ao_write.c @@ -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; -- 2.39.5