Skip to content

Don't let convert_av_frame_to_frame_output() take ownership of the AVFrame - #1595

Closed
NicolasHug wants to merge 2 commits into
mainfrom
borrowed_av_frames
Closed

Don't let convert_av_frame_to_frame_output() take ownership of the AVFrame#1595
NicolasHug wants to merge 2 commits into
mainfrom
borrowed_av_frames

Conversation

@NicolasHug

@NicolasHug NicolasHug commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

convert_av_frame_to_frame_output() took a non-const UniqueAVFrame&, which let implementations steal the caller's frame (by e.g. calling std::move() on it as done in the BetaCudaDeviceInterface)

This proved to cause subtle ownership issues as I started working on CUDA support for the "Blocks" API - the AVFrame that got std::moved() would be double-freed.

The parameter is now const, programatically enforcing that ownership remains to the caller.


Stack created with GitHub Stacks CLIGive Feedback 💬

convert_av_frame_to_frame_output() took a non-const UniqueAVFrame&, which
let implementations steal the caller's frame. Both CUDA interfaces did:
BetaCudaDeviceInterface moved out of it, and CudaDeviceInterface reassigned
it with the result of maybe_convert_av_frame_to_nv12_or_rgb24().

That was invisible under SingleStreamDecoder, whose frame is a loop local
that dies right after conversion. It is not invisible under the
building-block ops, where the frame is owned by a handle that outlives the
call: the frame ends up freed twice, corrupting the heap.

Take the frame by const reference all the way down the conversion path, so
a callee physically cannot move from it or reset it. Where an
implementation needs a different frame, it now owns that one separately and
binds a const reference to whichever of the two applies -- the idiom
convert_audio_av_frame_to_frame_output() already used.

maybe_convert_av_frame_to_nv12_or_rgb24() returns a null frame to mean "no
conversion needed" instead of handing back the input.
@pytorch-bot

pytorch-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1595

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit df0e0d2 with merge base 3f7692b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 3, 2026
@NicolasHug NicolasHug closed this Aug 4, 2026
@NicolasHug

Copy link
Copy Markdown
Contributor Author

Superseded by #1598

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant