Release detached seek frame when the FFmpeg video loop exits - #91
Closed
Blackspirits wants to merge 2 commits into
Closed
Blackspirits wants to merge 2 commits into
Blackspirits wants to merge 2 commits into
Conversation
Blackspirits
commented
Sep 13, 2026
Blackspirits
left a comment
Owner
Author
There was a problem hiding this comment.
Independent adversarial re-check: lastDropped is a detached VideoFrame owning unmanaged HGlobal memory. Normal presentation/serial-change paths null or return it, but teardown/exception could previously leave it unreachable. Moving ownership to the loop scope and returning it in finally is compatible with queue shutdown because VideoFrameQueue.Return disposes frames after Close. Full CI #34772887525 passed restore, build and the complete suite on the first run; UITests reported 5,150 passed, 9 skipped and 0 failed. Retry was not used. No blocker identified. Keep draft; no merge performed.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
During seek handling the video decoder may keep one converted frame in
lastDroppedwhile it advances from the key frame to the requested target. That frame is deliberately detached fromVideoFrameQueue: it is neither queued nor returned to the pool yet.If the session closes, the video loop exits, or an exception is thrown before a frame at/after the target is presented,
lastDroppedfalls out of scope without being returned.VideoFrameowns unmanaged memory allocated withMarshal.AllocHGlobal, and it has no finalizer, so this path leaks native memory.This change:
lastDroppedto the video-loop lifetime scope;VideoFrameQueue.Returnfromfinally;VideoFrameQueue.Returnto dispose it immediately when the queue has already been closed.Validation
f67b07f5b143fa47c87255ca1c3ed7adb3bd7142FfmpegPlayer.csVideoFrameowns an unmanagedHGlobaland has no finalizerSession.Disposecloses_videoFramesbefore joining the video thread, so returning a detached frame during loop teardown disposes it safelyAI assistance: ChatGPT was used to audit FFmpeg frame ownership across seek, fallback and teardown paths.