From ec2badbeddb969a93bfdd383c779190aa4b9ec70 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 24 Mar 2019 22:24:54 +0100 Subject: [PATCH] filter/ffmpeg: call av_frame_unref() before av_frame_get_buffer() av_frame_get_buffer() leaks memory if buffers were already allocated. Fixes one of the memory leaks of https://github.com/MusicPlayerDaemon/MPD/issues/514 --- src/filter/plugins/FfmpegFilter.cxx | 10 +++++++--- src/filter/plugins/FfmpegFilter.hxx | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/filter/plugins/FfmpegFilter.cxx b/src/filter/plugins/FfmpegFilter.cxx index f61d3415d..0bdae78e2 100644 --- a/src/filter/plugins/FfmpegFilter.cxx +++ b/src/filter/plugins/FfmpegFilter.cxx @@ -37,12 +37,12 @@ FfmpegFilter::FfmpegFilter(const AudioFormat &in_audio_format, graph(std::move(_graph)), buffer_src(std::move(_buffer_src)), buffer_sink(std::move(_buffer_sink)), + in_format(Ffmpeg::ToFfmpegSampleFormat(in_audio_format.format)), + in_sample_rate(in_audio_format.sample_rate), + in_channels(in_audio_format.channels), in_audio_frame_size(in_audio_format.GetFrameSize()), out_audio_frame_size(_out_audio_format.GetFrameSize()) { - in_frame->format = Ffmpeg::ToFfmpegSampleFormat(in_audio_format.format); - in_frame->sample_rate = in_audio_format.sample_rate; - in_frame->channels = in_audio_format.channels; } ConstBuffer @@ -50,6 +50,10 @@ FfmpegFilter::FilterPCM(ConstBuffer src) { /* submit source data into the FFmpeg audio buffer source */ + in_frame.Unref(); + in_frame->format = in_format; + in_frame->sample_rate = in_sample_rate; + in_frame->channels = in_channels; in_frame->nb_samples = src.size / in_audio_frame_size; in_frame.GetBuffer(); diff --git a/src/filter/plugins/FfmpegFilter.hxx b/src/filter/plugins/FfmpegFilter.hxx index 640a81eb3..0c6612a8b 100644 --- a/src/filter/plugins/FfmpegFilter.hxx +++ b/src/filter/plugins/FfmpegFilter.hxx @@ -32,6 +32,8 @@ class FfmpegFilter final : public Filter { Ffmpeg::FilterContext buffer_src, buffer_sink; Ffmpeg::Frame in_frame, out_frame; + const int in_format, in_sample_rate, in_channels; + const size_t in_audio_frame_size; const size_t out_audio_frame_size;