From c74b3059839036083f77729e36e392aa45e04cbd Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sun, 17 Feb 2019 13:12:29 +0100 Subject: [PATCH] [outputs] Fix crash, invalid reference to device after outputs_device_add --- src/outputs.c | 4 ++-- src/outputs.h | 5 ++++- src/player.c | 9 +++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/outputs.c b/src/outputs.c index adbf33e0..fd498b25 100644 --- a/src/outputs.c +++ b/src/outputs.c @@ -527,7 +527,7 @@ outputs_listener_notify(void) /* ---------------------------- Called by player ---------------------------- */ -int +struct output_device * outputs_device_add(struct output_device *add, bool new_deselect, int default_volume) { struct output_device *device; @@ -603,7 +603,7 @@ outputs_device_add(struct output_device *add, bool new_deselect, int default_vol listener_notify(LISTENER_SPEAKER); - return 0; + return device; } void diff --git a/src/outputs.h b/src/outputs.h index fb72041b..51bfa82f 100644 --- a/src/outputs.h +++ b/src/outputs.h @@ -266,7 +266,10 @@ outputs_listener_notify(void); /* ---------------------------- Called by player ---------------------------- */ -int +// Ownership of *add is transferred, so don't address after calling. Instead you +// can address the return value (which is not the same if the device was already +// in the list. +struct output_device * outputs_device_add(struct output_device *add, bool new_deselect, int default_volume); void diff --git a/src/player.c b/src/player.c index 4d3f2e58..7d560c24 100644 --- a/src/player.c +++ b/src/player.c @@ -794,8 +794,8 @@ session_update_read_next(void) static void session_update_read_eof(void) { - pb_session.reading_now->read_end = pb_session.pos - 1; - pb_session.reading_now->play_end = pb_session.pos - 1 + pb_session.reading_now->output_buffer_samples; + pb_session.reading_now->read_end = pb_session.pos; + pb_session.reading_now->play_end = pb_session.pos + pb_session.reading_now->output_buffer_samples; source_free(&pb_session.reading_prev); pb_session.reading_prev = pb_session.reading_now; @@ -1196,9 +1196,10 @@ device_add(void *arg, int *retval) // Never turn on new devices during playback new_deselect = (player_state == PLAY_PLAYING); - *retval = outputs_device_add(device, new_deselect, default_volume); + device = outputs_device_add(device, new_deselect, default_volume); + *retval = device ? 0 : -1; - if (device->selected) + if (device && device->selected) speaker_select_output(device); return COMMAND_END;