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
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);
}
}