From 08fc6694e1adf98014d3fdfa3d4cfd886618aba0 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 11 Apr 2021 13:07:44 +0200 Subject: [PATCH] Do not destroy uninitialized screen When --no-display was passed, screen_destroy() was called while screen_init() was never called. In practice, it did not crash because it just freed NULL pointers, but it was still incorrect. --- app/src/scrcpy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index f996f2cf..6278cfd7 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -282,6 +282,7 @@ scrcpy(const struct scrcpy_options *options) { bool stream_started = false; bool controller_initialized = false; bool controller_started = false; + bool screen_initialized = false; bool record = !!options->record_filename; struct server_params params = { @@ -399,6 +400,7 @@ scrcpy(const struct scrcpy_options *options) { &screen_params)) { goto end; } + screen_initialized = true; if (options->turn_screen_off) { struct control_msg msg; @@ -427,9 +429,11 @@ scrcpy(const struct scrcpy_options *options) { ret = event_loop(options); LOGD("quit..."); - screen_destroy(&screen); - end: + if (screen_initialized) { + screen_destroy(&screen); + } + // stop stream and controller so that they don't continue once their socket // is shutdown if (stream_started) {