Skip to content

Commit

Permalink
FFmpegWriter: Free any old context before clobbering
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferdnyc committed Mar 22, 2020
1 parent f9a91a5 commit 9998876
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FFmpegWriter.cpp
Expand Up @@ -1067,6 +1067,11 @@ AVStream *FFmpegWriter::add_audio_stream() {
if (codec == NULL)
throw InvalidCodec("A valid audio codec could not be found for this file.", path);

// Free any previous memory allocations
if (audio_codec_ctx != NULL) {
AV_FREE_CONTEXT(audio_codec_ctx);
}

// Create a new audio stream
AV_FORMAT_NEW_STREAM(oc, audio_codec_ctx, codec, st)

Expand Down

0 comments on commit 9998876

Please sign in to comment.