From: Pali Rohár Date: Tue, 27 Aug 2019 03:11:27 +0000 (+0530) Subject: bluetooth: Only perform write-related calculations when we have a sink X-Git-Tag: v12.99.3~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bdf66c4693c8775dc3c4a403cbae77a56d4b1e29;p=platform%2Fupstream%2Fpulseaudio.git bluetooth: Only perform write-related calculations when we have a sink This avoids a potential divide-by-zero when we try to decide how much to write to the sink in the source thread when there is no sink. Fixes https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/717 --- diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c index a164d81..cff1cd6 100644 --- a/src/modules/bluetooth/module-bluez5-device.c +++ b/src/modules/bluetooth/module-bluez5-device.c @@ -1378,7 +1378,7 @@ static void thread_func(void *userdata) { if (have_source) { /* We should send two blocks to the device before we expect a response. */ - if (u->write_index == 0 && u->read_index <= 0) + if (have_sink && u->write_index == 0 && u->read_index <= 0) blocks_to_write = 2; /* If we got woken up by POLLIN let's do some reading */ @@ -1393,7 +1393,7 @@ static void thread_func(void *userdata) { if (n_read < 0) goto fail; - if (n_read > 0) { + if (have_sink && n_read > 0) { /* We just read something, so we are supposed to write something, too */ bytes_to_write += n_read; blocks_to_write += bytes_to_write / u->write_block_size;