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.
This commit is contained in:
FeRD (Frank Dana)
2020-03-22 12:19:11 -04:00
parent f9a91a5a92
commit 999887687c

View File

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