Skip to content

fix(media-io): free the last packet of a cancelled remux (#3365) - #3432

Merged
vpacher merged 2 commits into
masterfrom
fix/3365-remux-cancel-packet
Nov 1, 2026
Merged

vpacher merged 2 commits into
masterfrom
fix/3365-remux-cancel-packet

Conversation

@vpacher

@vpacher vpacher commented Nov 1, 2026

Copy link
Copy Markdown
Member

Refs #3365, #3238.

Why

test_media_remux leaks one packet buffer in every asan run (24 + 16448 + 48 bytes, first allocated in avformat_find_stream_info() under media_remux_job_create()). 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 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

  • On the stop from the progress callback, process_packets() unrefs the packet it just read before it returns: host.packet_unref() in the Rust port (a new Host method, obs_media_remux_packet_unref() in the adapter), and av_packet_unref(&pkt) before the break in the C remux. Both sides make the same calls at the same point, so the Tier 3 parity tests stay equal.
  • The test_media_remux entry leaves the sanitizer known list. The triage tests that used it as their known example use test_media_alpha_network now.

test_media_alpha_network keeps 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

  • RED 21bad07: 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. Fails stopping_from_the_callback_unrefs_the_packet_it_read (the read is followed by write_trailer).
  • GREEN 7cbf892: the fix.

Tests

test_media_remux through the sanitizer harness (asan build) on a local build box:

  • RED (master): 3 leak records, 16520 bytes in 3 allocations; 13/13 cases pass.
  • GREEN: no leak; 13/13 cases pass.

obs-media-io remux 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

🤖 Generated with Claude Code

vpacher and others added 2 commits November 1, 2026 15:46
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
vpacher requested a review from zackees as a code owner November 1, 2026 14:56
@vpacher
vpacher enabled auto-merge November 1, 2026 14:56

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vpacher
vpacher added this pull request to the merge queue Nov 1, 2026
Merged via the queue into master with commit 830aae8 Nov 1, 2026
37 checks passed
@vpacher
vpacher deleted the fix/3365-remux-cancel-packet branch November 1, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants