From 46f691817983c8c251956e5115ace6a8af8e08d4 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 10 Mar 2023 22:42:59 +0100 Subject: [PATCH] Stop and join sc_file_pusher only if initialized The sc_file_pusher is lazy-initialized, but it was stopped and joined in all cases (accessing uninitialized values). Detected by poisoning the struct scrcpy instance with ASAN enabled. --- app/src/file_pusher.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/file_pusher.c b/app/src/file_pusher.c index b49e93e5..06911052 100644 --- a/app/src/file_pusher.c +++ b/app/src/file_pusher.c @@ -172,14 +172,18 @@ sc_file_pusher_start(struct sc_file_pusher *fp) { void sc_file_pusher_stop(struct sc_file_pusher *fp) { - sc_mutex_lock(&fp->mutex); - fp->stopped = true; - sc_cond_signal(&fp->event_cond); - sc_intr_interrupt(&fp->intr); - sc_mutex_unlock(&fp->mutex); + if (fp->initialized) { + sc_mutex_lock(&fp->mutex); + fp->stopped = true; + sc_cond_signal(&fp->event_cond); + sc_intr_interrupt(&fp->intr); + sc_mutex_unlock(&fp->mutex); + } } void sc_file_pusher_join(struct sc_file_pusher *fp) { - sc_thread_join(&fp->thread, NULL); + if (fp->initialized) { + sc_thread_join(&fp->thread, NULL); + } }