Repository navigation
fix(media-io): free the last packet of a cancelled remux (#3365) - #3432
Merged
Merged
Conversation
process_packets() reads each packet into one AVPacket and unrefs it after the write. When the progress callback stops the job, the C remux (media-remux.c.h) breaks out of its loop and the Rust port returns, both before the write, so the buffer of that last packet leaked (LeakSanitizer in test_media_remux: 24 + 16448 + 48 bytes, allocated in avformat_find_stream_info under media_remux_job_create). Host gets packet_unref(), backed by obs_media_remux_packet_unref() in the adapter, and a Tier 1 test checks that a job stopped from the callback unrefs the packet right after the last read. The known-list entry of test_media_remux goes, and the triage tests that used it as their known example use test_media_alpha_network. That test keeps its entry: its leak is in FFmpeg itself (#3365). Fails: stopping_from_the_callback_unrefs_the_packet_it_read (the read is followed by write_trailer, not packet_unref). Co-Authored-By: Claude Opus 5.5 <[email protected]>
) When the progress callback stops the job, process_packets() unrefs the packet it just read before it returns: host.packet_unref() in the Rust port, av_packet_unref(&pkt) before the break in the C remux, at the same point, so both make the same calls (Tier 3 parity) and neither leaks the packet. obs-media-io remux tests: 44 passed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=67807fac6b1aea0158715c346cabfb2dc3ba24c3 secs=279 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a Ci-Attestation: {"at":1793544685,"gate":"rust/all/fmt","host":"linux-x86_64","key":"5b3b7f34994b3579d7c77e89097123f5b6d7f8a4a813181ebba02f9ea1b01643","lane":"lint","parents":["21bad07c36d69898537262a1d7409ab426e851eb"],"secs":76,"stamp":"9d85a48c84a5b9e959f929775ad94179","tree":"67807fac6b1aea0158715c346cabfb2dc3ba24c3","v":1,"via":"run"} Ci-Attestation: {"at":1793544685,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"5b3b7f34994b3579d7c77e89097123f5b6d7f8a4a813181ebba02f9ea1b01643","lane":"lint","parents":["21bad07c36d69898537262a1d7409ab426e851eb"],"secs":76,"stamp":"bf8bc761d60c83ef3aaf4d62fb94e5a0","tree":"67807fac6b1aea0158715c346cabfb2dc3ba24c3","v":1,"via":"run"} Ci-Attestation: {"at":1793544685,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"43094bbc330161b73345f8a4251b1394e7d26298df7ae0e67a849d97e225ed90","lane":"rust-test","parents":["21bad07c36d69898537262a1d7409ab426e851eb"],"secs":85,"stamp":"2b7482852f99699f557c89db4bff863a","tree":"67807fac6b1aea0158715c346cabfb2dc3ba24c3","v":1,"via":"run"} Ci-Attestation: {"at":1793544685,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"2f5f3d718473170b1ecda502ceb1a7710155dffc900a0268425b3b895749575e","lane":"cross","parents":["21bad07c36d69898537262a1d7409ab426e851eb"],"secs":57,"stamp":"4e7cdd4ef4bf16b0bb9f22e4a8ed645c","tree":"67807fac6b1aea0158715c346cabfb2dc3ba24c3","v":1,"via":"run"} Ci-Attestation: {"at":1793544685,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"2f5f3d718473170b1ecda502ceb1a7710155dffc900a0268425b3b895749575e","lane":"cross","parents":["21bad07c36d69898537262a1d7409ab426e851eb"],"secs":57,"stamp":"604da1ab828f62708b988a6dcb4711ff","tree":"67807fac6b1aea0158715c346cabfb2dc3ba24c3","v":1,"via":"run"} Ci-Attestation: {"at":1793544685,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"2f5f3d718473170b1ecda502ceb1a7710155dffc900a0268425b3b895749575e","lane":"cross","parents":["21bad07c36d69898537262a1d7409ab426e851eb"],"secs":57,"stamp":"f74d5c0e5e379e06e2f611a031091076","tree":"67807fac6b1aea0158715c346cabfb2dc3ba24c3","v":1,"via":"run"} Ci-Attestation: {"at":1793544685,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"2f5f3d718473170b1ecda502ceb1a7710155dffc900a0268425b3b895749575e","lane":"cross","parents":["21bad07c36d69898537262a1d7409ab426e851eb"],"secs":57,"stamp":"424301c94e2ac57a6efc242265a9a874","tree":"67807fac6b1aea0158715c346cabfb2dc3ba24c3","v":1,"via":"run"} Ci-Attestation: {"at":1793544685,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"d82f36b7c2e5062510ee4387727dee2c4918c72eb14a6f71bd216056edd137a7","lane":"tier2-linux","parents":["21bad07c36d69898537262a1d7409ab426e851eb"],"secs":279,"stamp":"9de487c200062aef87ba5eb644bcf1ff","tree":"67807fac6b1aea0158715c346cabfb2dc3ba24c3","v":1,"via":"run"}
vpacher
enabled auto-merge
November 1, 2026 14:56
zackees
approved these changes
Nov 1, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Coordinator review: LGTM. The stop path now unrefs the packet in both the C reference (media-remux.c.h) and the Rust port, so the differential tests keep comparing like with like. The unref goes through a small C shim (obs_media_remux_packet_unref), so no FFmpeg symbol is added to the Rust side. The known-list entry is dropped, and ci/test_sanitize_triage.py moves its fixture to another known entry, which is right. If this leak comes back, the asan lane catches it.
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.
Refs #3365, #3238.
Why
test_media_remuxleaks one packet buffer in every asan run (24 + 16448 + 48 bytes, first allocated inavformat_find_stream_info()undermedia_remux_job_create()).process_packets()reads each packet into oneAVPacketand unrefs it after the write. When the progress callback stops the job, the C remux (media-remux.c.h) breaks out of its loop and the Rust port returns, both before that write, so the buffer of the last packet read leaks in both. Only the hybrid build runs under asan, so only the port showed it.What changes
process_packets()unrefs the packet it just read before it returns:host.packet_unref()in the Rust port (a newHostmethod,obs_media_remux_packet_unref()in the adapter), andav_packet_unref(&pkt)before thebreakin the C remux. Both sides make the same calls at the same point, so the Tier 3 parity tests stay equal.test_media_remuxentry leaves the sanitizer known list. The triage tests that used it as their known example usetest_media_alpha_networknow.test_media_alpha_networkkeeps its entry. Its leak is in FFmpeg itself: a minimal program that only opens, probes and closes the test's VP9-alpha clip (avformat_open_input,avformat_find_stream_info,avformat_close_input) leaks the same 480 + 8242 + 960 bytes in 60 allocations with FFmpeg 8.0.1 and no OBS code. That part stays on #3365.Commits
Host::packet_unref()and a Tier 1 test that a job stopped from the callback unrefs the packet right after its last read; the known-list change. Failsstopping_from_the_callback_unrefs_the_packet_it_read(the read is followed bywrite_trailer).Tests
test_media_remuxthrough the sanitizer harness (asan build) on a local build box:obs-media-ioremux tests (Tier 1 and the Tier 3 parity against the C remux): 44 passed.Test cost: one new Tier 1 test on the fake host, under 1 ms, no allocation beyond its log, no own threads.
Tier 2 passes in the local gate. Local gate, stamped head 7cbf892: 4 min 39 s (lint 76 s, rust-test 85 s, cross 57 s, tier2-linux 279 s).
Checklist
master🤖 Generated with Claude Code