Skip to content

Commit a5c994c

Browse files
claudeJackLau1222
authored andcommitted
transcoder_ffmpeg: fix memleak of encoder fmtCtx and filter_graph
- Call avformat_free_context on encoder->fmtCtx in cleanup to free streams, codec contexts, codec parameters, and internal packets allocated by avformat_alloc_output_context2 and avformat_write_header - Free filter_graph in init_filter when an error occurs before it is assigned to filter_ctx->filter_graph Signed-off-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b70d9c0 commit a5c994c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/transcoder/src/transcoder_ffmpeg.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ int TranscoderFFmpeg::init_filter(AVCodecContext *dec_ctx, FilteringContext *fil
195195
end:
196196
avfilter_inout_free(&inputs);
197197
avfilter_inout_free(&outputs);
198-
198+
if (ret < 0)
199+
avfilter_graph_free(&filter_graph);
199200
return ret;
200201
}
201202

@@ -541,8 +542,11 @@ bool TranscoderFFmpeg::transcode(std::string input_path,
541542
decoder = nullptr;
542543
}
543544

544-
if (encoder && encoder->fmtCtx && !(encoder->fmtCtx->oformat->flags & AVFMT_NOFILE)) {
545-
avio_closep(&encoder->fmtCtx->pb);
545+
if (encoder && encoder->fmtCtx) {
546+
if (!(encoder->fmtCtx->oformat->flags & AVFMT_NOFILE))
547+
avio_closep(&encoder->fmtCtx->pb);
548+
avformat_free_context(encoder->fmtCtx);
549+
encoder->fmtCtx = NULL;
546550
}
547551
if (encoder) {
548552
delete encoder;

0 commit comments

Comments
 (0)