Skip to content

Commit b47d015

Browse files
runningcodeclaude
andcommitted
fix(replay): Release MediaMuxer when no frames are encoded
The MediaMuxer is created when the video encoder is constructed, but its release() was reachable only on the happy path. Two cases leaked it: - createVideoOf returned early when frameCount was 0 without releasing the encoder. - SimpleMp4FrameMuxer.release() called muxer.stop() before muxer.release(). stop() throws if the muxer was never started (no frame ever muxed), so release() was skipped. This surfaced as a CloseGuard "resource was acquired but never released" warning. Guard stop() behind the started flag so release() is always reached, and release the encoder on the no-frames return path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 05aa61d commit b47d015

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayCache.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ public class ReplayCache(private val options: SentryOptions, private val replayI
199199

200200
if (frameCount == 0) {
201201
options.logger.log(DEBUG, "Generated a video with no frames, not capturing a replay segment")
202+
encoderLock.acquire().use {
203+
encoder?.release()
204+
encoder = null
205+
}
202206
deleteFile(videoFile)
203207
return null
204208
}

sentry-android-replay/src/main/java/io/sentry/android/replay/video/SimpleMp4FrameMuxer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ internal class SimpleMp4FrameMuxer(path: String, fps: Float) : SimpleFrameMuxer
6767
}
6868

6969
override fun release() {
70-
muxer.stop()
70+
// stop() throws if the muxer was never started (e.g. no frame was ever muxed), so we guard it
71+
// to ensure release() is always reached and the underlying resources are freed
72+
if (started) {
73+
muxer.stop()
74+
}
7175
muxer.release()
7276
}
7377

0 commit comments

Comments
 (0)