ref:7ecd0286644590c4214688c8dc1d4bd28f28eafd

fix(video): avoid UAF crashes during video reinit (reproducible on Vulkan) (#5346)

SHA: 7ecd0286644590c4214688c8dc1d4bd28f28eafd
Author: Conn O'Griofa <connogriofa@gmail.com>
Date: 2026-06-28 14:45
Parents: fcc4395
1 files changed +14 -11
Type
src/video.cpp +14 −11
@@ -2389,17 +2389,6 @@
}
while (true) {
// Break out of the encoding loop if any of the following are true:
// a) The stream is ending
// b) Sunshine is quitting
// c) The capture side is waiting to reinit and we've encoded at least one frame
//
// If we have to reinit before we have received any captured frames, we will encode
// the blank dummy frame just to let Moonlight know that we're alive.
if (shutdown_event->peek() || !images->running() || (reinit_event.peek() && frame_nr > 1)) {
break;
}
bool requested_idr_frame = false;
while (invalidate_ref_frames_events->peek()) {
@@ -2430,6 +2419,20 @@
} else if (!images->running()) {
break;
}
}
// Break out of the encoding loop if any of the following are true:
// a) The stream is ending
// b) Sunshine is quitting
// c) The capture side is waiting to reinit and we've encoded at least one frame
//
// If we have to reinit before we have received any captured frames, we will encode
// the blank dummy frame just to let Moonlight know that we're alive.
//
// Ensure that this check occurs as close as possible to the encode call to prevent packets
// in flight after encoder teardown.
if (shutdown_event->peek() || !images->running() || (reinit_event.peek() && frame_nr > 1)) {
break;
}
if (encode(frame_nr++, *session, packets, channel_data, frame_timestamp)) {