Skip to content

Commit

Permalink
Destroy screen once stream is finished
Browse files Browse the repository at this point in the history
The screen receives callbacks from the decoder, fed by the stream.

The decoder is run from the stream thread, so waiting for the end of
stream is sufficient to avoid possible use-after-destroy.
  • Loading branch information
rom1v committed Apr 11, 2021
1 parent 08fc669 commit 28f6cba
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,6 @@ scrcpy(const struct scrcpy_options *options) {
LOGD("quit...");

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 All @@ -459,6 +455,13 @@ scrcpy(const struct scrcpy_options *options) {
if (stream_started) {
stream_join(&stream);
}

// Destroy the screen only after the stream is guaranteed to be finished,
// because otherwise the screen could receive new frames after destruction
if (screen_initialized) {
screen_destroy(&screen);
}

if (controller_started) {
controller_join(&controller);
}
Expand Down

0 comments on commit 28f6cba

Please sign in to comment.