From 0a3d2e127fcc13d81f38670770bfe602987825b7 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 17 Oct 2019 16:36:33 -0700 Subject: [PATCH] libobs: Fix race condition It is possible for a GPU encoder to be in a destruction state while still in the GPU encoder list, although very rare. --- libobs/obs-video-gpu-encode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libobs/obs-video-gpu-encode.c b/libobs/obs-video-gpu-encode.c index 808b55c3c..bec537d2c 100644 --- a/libobs/obs-video-gpu-encode.c +++ b/libobs/obs-video-gpu-encode.c @@ -58,9 +58,10 @@ static void *gpu_encode_thread(void *unused) video_output_inc_texture_frames(video->video); for (size_t i = 0; i < video->gpu_encoders.num; i++) { - obs_encoder_t *encoder = video->gpu_encoders.array[i]; - da_push_back(encoders, &encoder); - obs_encoder_addref(encoder); + obs_encoder_t *encoder = obs_encoder_get_ref( + video->gpu_encoders.array[i]); + if (encoder) + da_push_back(encoders, &encoder); } pthread_mutex_unlock(&video->gpu_encoder_mutex);