Skip to content

Replay: MediaMuxer resource leak when a segment has no encodable frames #5584

Description

@runningcode

Problem

The MediaMuxer inside SimpleMp4FrameMuxer is constructed eagerly when the replay video encoder is created (CloseGuard.open registers a guard expecting release()), but release() was only reachable on the happy path. Two cases leaked it:

  • ReplayCache.createVideoOf returned early when frameCount == 0 (frames exist but none could be encoded) without calling encoder?.release().
  • SimpleMp4FrameMuxer.release() called muxer.stop() before muxer.release(). MediaMuxer.stop() throws IllegalStateException if the muxer was never started (no frame ever muxed, so INFO_OUTPUT_FORMAT_CHANGED never fired), so muxer.release() was skipped. The exception was then swallowed by SimpleVideoEncoder.release()'s catch block.

Surfaces as a CloseGuard warning: A resource was acquired at attached stack trace but never released ... Explicit termination method 'release' not called, pointing at the MediaMuxer constructor in SimpleMp4FrameMuxer. It is a latent native resource leak whenever a replay segment ends up with zero encodable frames.

Fix

Guard stop() behind the started flag so release() is always reached, and release the encoder on the no-frames return path.

Fixed in PR #5583.

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions