From e13dd533764a37bfaa33b51f7aa832e3ac1f17ac Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 21 Jun 2016 04:06:35 -0700 Subject: [PATCH] libobs: Fix output shutdown order When obs_output_actual_stop is called on shutdown, it should wait for the output to fully stop before doing anything, and then it should wait for the data capture to end. The service should not be removed until after the output has stopped, otherwise it could result in a possible memory leak on stop. Packets should be freed last. --- libobs/obs-output.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libobs/obs-output.c b/libobs/obs-output.c index e7846eba2..2141590b2 100644 --- a/libobs/obs-output.c +++ b/libobs/obs-output.c @@ -170,16 +170,18 @@ void obs_output_destroy(obs_output_t *output) if (output->valid && active(output)) obs_output_actual_stop(output, true, 0); - if (output->service) - output->service->output = NULL; + os_event_wait(output->stopping_event); if (data_capture_ending(output)) pthread_join(output->end_data_capture_thread, NULL); - free_packets(output); + if (output->service) + output->service->output = NULL; if (output->context.data) output->info.destroy(output->context.data); + free_packets(output); + if (output->video_encoder) { obs_encoder_remove_output(output->video_encoder, output);