[FFmpeg-devel] [PATCH 2/3] examples/filtering_audio: Fix memory leak
pkoshevoy at gmail.com
pkoshevoy at gmail.com
Thu Apr 18 07:38:26 CEST 2013
From: Pavel Koshevoy <pkoshevoy at gmail.com>
Calling av_opt_set_int(dec_ctx, "refcounted_frames", 1, 0)
introduced a memory leak which was reported by valgrind.
I don't know if my fix is correct, but it fixes the leak.
Signed-off-by: Pavel Koshevoy <pkoshevoy at gmail.com>
---
doc/examples/filtering_audio.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
index f674052..7a47fbc 100644
--- a/doc/examples/filtering_audio.c
+++ b/doc/examples/filtering_audio.c
@@ -71,7 +71,6 @@ static int open_input_file(const char *filename)
}
audio_stream_index = ret;
dec_ctx = fmt_ctx->streams[audio_stream_index]->codec;
- av_opt_set_int(dec_ctx, "refcounted_frames", 1, 0);
/* init the audio decoder */
if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) {
@@ -190,10 +189,9 @@ int main(int argc, char **argv)
int ret;
AVPacket packet;
AVFrame *frame = av_frame_alloc();
- AVFrame *filt_frame = av_frame_alloc();
int got_frame;
- if (!frame || !filt_frame) {
+ if (!frame) {
perror("Could not allocate frame");
exit(1);
}
@@ -227,20 +225,21 @@ int main(int argc, char **argv)
if (got_frame) {
/* push the audio data from decoded frame into the filtergraph */
- if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
+ if (av_buffersrc_write_frame(buffersrc_ctx, frame) < 0) {
av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");
break;
}
/* pull filtered audio from the filtergraph */
while (1) {
- ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
+ avcodec_get_frame_defaults(frame);
+ ret = av_buffersink_get_frame(buffersink_ctx, frame);
if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
break;
if(ret < 0)
goto end;
- print_frame(filt_frame);
- av_frame_unref(filt_frame);
+ print_frame(frame);
+ av_frame_unref(frame);
}
}
}
@@ -252,7 +251,6 @@ end:
avcodec_close(dec_ctx);
avformat_close_input(&fmt_ctx);
av_frame_free(&frame);
- av_frame_free(&filt_frame);
if (ret < 0 && ret != AVERROR_EOF) {
char buf[1024];
--
1.7.10.4
More information about the ffmpeg-devel
mailing list