[FFmpeg-devel] [PATCH 1/2] avfilter/asrc_sinc: fix leak in config_input()

Lidong Yan yldhome2d2 at gmail.com
Wed Jun 25 18:38:30 EEST 2025


In config_input(), fir_to_phase() allocates memory in h[longer].
But if av_calloc() to s->coeffs failed, memory in h[longer] would
leak. Also noticed that after fir_to_phase() there are three return
point, two of them didn't free h[longer]. However, the first return
points means fir_to_phase() failed, which in turn means that memory
in h[longer] has not been allocated yet. To fix this leak, add
av_free(h[longer]) in av_calloc() failed branch would be enough.

Signed-off-by: Lidong Yan <502024330056 at smail.nju.edu.cn>
---
 libavfilter/asrc_sinc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index 6ff3303316..198c322665 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -370,8 +370,10 @@ static int config_output(AVFilterLink *outlink)
     s->n = 1 << (av_log2(n) + 1);
     s->rdft_len = 1 << av_log2(n);
     s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));
-    if (!s->coeffs)
+    if (!s->coeffs) {
+        av_free(h[longer]);
         return AVERROR(ENOMEM);
+    }
 
     for (i = 0; i < n; i++)
         s->coeffs[i] = h[longer][i];
-- 
2.50.0.108.g6ae0c543ae



More information about the ffmpeg-devel mailing list