From e31f38da1337c4622e4a1f833680a8789777d8ef Mon Sep 17 00:00:00 2001 From: Sagar Nm Date: Thu, 19 Mar 2015 16:09:29 +0530 Subject: [PATCH 1/1] Fix PulseAudio crash during remote device unpair --- src/modules/bluetooth/module-bluez5-device.c | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c index 7238e6f..14385ea 100644 --- a/src/modules/bluetooth/module-bluez5-device.c +++ b/src/modules/bluetooth/module-bluez5-device.c @@ -509,7 +509,10 @@ static int a2dp_process_render(struct userdata *u) { break; pa_log_error("Failed to write data to socket: %s", pa_cstrerror(errno)); - ret = -1; + if (errno == EPIPE || errno == ENOTCONN || errno == ECONNRESET) + ret = -2; + else + ret = -1; break; } @@ -1453,8 +1456,14 @@ static void thread_func(void *userdata) { u->started_at = pa_rtclock_now(); if (u->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK) { - if ((n_written = a2dp_process_render(u)) < 0) - goto fail; + if ((n_written = a2dp_process_render(u)) < 0) { + if (n_written == -2) { + transport_release(u); + goto io_fail; + } + else + goto fail; + } } else { if ((n_written = sco_process_render(u)) < 0) goto fail; @@ -1505,6 +1514,20 @@ static void thread_func(void *userdata) { transport_release(u); goto finish; } + +io_fail: + if (disable_timer) + pa_rtpoll_set_timer_disabled(u->rtpoll); + + if ((ret = pa_rtpoll_run(u->rtpoll)) < 0) { + pa_log_debug("pa_rtpoll_run failed with: %d", ret); + goto fail; + } + if (ret == 0) { + pa_log_debug("IO thread shutdown requested, stopping cleanly"); + transport_release(u); + goto finish; + } } fail: -- 1.7.9.5