[outputs] Fix crash, invalid reference to device after outputs_device_add

This commit is contained in:
ejurgensen 2019-02-17 13:12:29 +01:00
parent b7add1d0fa
commit c74b305983
3 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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;