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

This commit is contained in:
Conn O'Griofa
2026-06-28 15:45:45 +01:00
committed by GitHub
parent fcc439501f
commit 7ecd028664
+14 -11
View File
@@ -2389,17 +2389,6 @@ namespace video {
}
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()) {
@@ -2432,6 +2421,20 @@ namespace video {
}
}
// 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)) {
BOOST_LOG(error) << "Could not encode video packet"sv;
return;