From f3fa3a91c0d9f59bc1db5673daa4228deb53a138 Mon Sep 17 00:00:00 2001 From: Rakesh M K Date: Fri, 20 Mar 2015 16:49:51 +0530 Subject: [PATCH 1/1] bluez5 : Fix pulseaudio crash during unpair When remote headset is unpaired or disconnected, blueZ will call "ClearConfiguration" Dbus method. Which will update the transport state to disconnected. Due to which the STOP thread will be handled. When Stop thread handling is in progress, rendering thread will post the "BLUETOOTH_MESSAGE_IO_THREAD_FAILED" due to audio packet pa_write() fail. Since processing of message is done inside the stop_thread() which internally calls the Stop_thread() one more time. Further access pa msgQue memory which is already freed will leads to the pulseAudio crash. This patch will avoid the recursive calling of stop_thread(). 0 0x406129e8 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:67 wait_op=false) at pulsecore/asyncmsgq.c:177 --- src/modules/bluetooth/module-bluez5-device.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c index 7238e6f..e9b4ccc 100644 --- a/src/modules/bluetooth/module-bluez5-device.c +++ b/src/modules/bluetooth/module-bluez5-device.c @@ -122,6 +122,7 @@ struct userdata { pa_rtpoll *rtpoll; pa_rtpoll_item *rtpoll_item; bluetooth_msg *msg; + bool stop_thread_initiated; int stream_fd; int stream_write_type; @@ -1557,6 +1558,12 @@ static int start_thread(struct userdata *u) { static void stop_thread(struct userdata *u) { pa_assert(u); + /*To avoid the recusive call of stop_thread*/ + if (u->stop_thread_initiated) + return; + + u->stop_thread_initiated = true; + if (u->sink) pa_sink_unlink(u->sink); @@ -1599,6 +1606,7 @@ static void stop_thread(struct userdata *u) { pa_smoother_free(u->read_smoother); u->read_smoother = NULL; } + u->stop_thread_initiated = false; } /* Run from main thread */ @@ -2133,6 +2141,7 @@ int pa__init(pa_module* m) { m->userdata = u = pa_xnew0(struct userdata, 1); u->module = m; u->core = m->core; + u->stop_thread_initiated = false; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log_error("Failed to parse module arguments"); -- 1.7.9.5