Skip to content

Commit 9998876

Browse files
committed
FFmpegWriter: Free any old context before clobbering
valgrind caught that AVFORMAT_NEW_STREAM() could be leaking pointers when calling avcodec_alloc_context3(), if there's an existing context already assigned. So we check and free it first, if necessary.
1 parent f9a91a5 commit 9998876

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/FFmpegWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,11 @@ AVStream *FFmpegWriter::add_audio_stream() {
10671067
if (codec == NULL)
10681068
throw InvalidCodec("A valid audio codec could not be found for this file.", path);
10691069

1070+
// Free any previous memory allocations
1071+
if (audio_codec_ctx != NULL) {
1072+
AV_FREE_CONTEXT(audio_codec_ctx);
1073+
}
1074+
10701075
// Create a new audio stream
10711076
AV_FORMAT_NEW_STREAM(oc, audio_codec_ctx, codec, st)
10721077

0 commit comments

Comments
 (0)