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.
This commit is contained in:
Romain Vimont 2021-04-11 13:07:44 +02:00
parent d0983db592
commit 08fc6694e1

View File

@ -282,6 +282,7 @@ scrcpy(const struct scrcpy_options *options) {
bool stream_started = false; bool stream_started = false;
bool controller_initialized = false; bool controller_initialized = false;
bool controller_started = false; bool controller_started = false;
bool screen_initialized = false;
bool record = !!options->record_filename; bool record = !!options->record_filename;
struct server_params params = { struct server_params params = {
@ -399,6 +400,7 @@ scrcpy(const struct scrcpy_options *options) {
&screen_params)) { &screen_params)) {
goto end; goto end;
} }
screen_initialized = true;
if (options->turn_screen_off) { if (options->turn_screen_off) {
struct control_msg msg; struct control_msg msg;
@ -427,9 +429,11 @@ scrcpy(const struct scrcpy_options *options) {
ret = event_loop(options); ret = event_loop(options);
LOGD("quit..."); LOGD("quit...");
screen_destroy(&screen);
end: end:
if (screen_initialized) {
screen_destroy(&screen);
}
// stop stream and controller so that they don't continue once their socket // stop stream and controller so that they don't continue once their socket
// is shutdown // is shutdown
if (stream_started) { if (stream_started) {