Skip to content

Commit f037273

Browse files
runningcodeclaude
andauthored
fix(replay): Release MediaMuxer when no frames are encoded (#5583)
* 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> * changelog --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0c118e9 commit f037273

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Release `MediaMuxer` when a replay segment has no encodable frames to avoid a resource leak ([#5583](https://github.com/getsentry/sentry-java/pull/5583))
8+
39
## 8.44.1
410

511
### Fixes

‎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)