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.
This commit is contained in:
Romain Vimont 2023-03-10 22:42:59 +01:00
parent d93582724d
commit 46f6918179

View file

@ -172,14 +172,18 @@ sc_file_pusher_start(struct sc_file_pusher *fp) {
void void
sc_file_pusher_stop(struct sc_file_pusher *fp) { sc_file_pusher_stop(struct sc_file_pusher *fp) {
if (fp->initialized) {
sc_mutex_lock(&fp->mutex); sc_mutex_lock(&fp->mutex);
fp->stopped = true; fp->stopped = true;
sc_cond_signal(&fp->event_cond); sc_cond_signal(&fp->event_cond);
sc_intr_interrupt(&fp->intr); sc_intr_interrupt(&fp->intr);
sc_mutex_unlock(&fp->mutex); sc_mutex_unlock(&fp->mutex);
} }
}
void void
sc_file_pusher_join(struct sc_file_pusher *fp) { sc_file_pusher_join(struct sc_file_pusher *fp) {
if (fp->initialized) {
sc_thread_join(&fp->thread, NULL); sc_thread_join(&fp->thread, NULL);
} }
}