Skip to content

Commit

Permalink
Do not destroy uninitialized screen
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rom1v committed Apr 11, 2021
1 parent d0983db commit 08fc669
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 08fc669

Please sign in to comment.