PR #21452 opened by realies
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21452
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21452.patch

The limiter_buf was being allocated with buf_size (3000ms worth of
samples) instead of limiter_buf_size (210ms worth of samples).

This resulted in allocating approximately 14x more memory than needed
for the limiter buffer.

## Memory profiling results (valgrind massif, 192kHz stereo)

| Version | Peak Heap Allocation |
|---------|---------------------|
| Before  | 87,415,378 bytes (~83.4 MB) |
| After   | 79,075,138 bytes (~75.4 MB) |
| **Saved** | **8,340,240 bytes (~8.0 MB)** |

## Details

At 192kHz stereo:
- buf_size: 1,152,000 samples = 9.2 MB
- limiter_buf_size: 80,640 samples = 0.6 MB
- Wasted per instance: ~8.6 MB

The bug was introduced when the limiter buffer was added but the
wrong size variable was used in av_malloc_array().


>From e413d357c0b8a250ccf4efb4b61fc4fd323db297 Mon Sep 17 00:00:00 2001
From: realies <[email protected]>
Date: Tue, 13 Jan 2026 19:34:00 +0200
Subject: [PATCH] avfilter/af_loudnorm: fix limiter buffer over-allocation

The limiter_buf was being allocated with buf_size (3000ms worth of
samples) instead of limiter_buf_size (210ms worth of samples).

This resulted in allocating approximately 14x more memory than needed
for the limiter buffer. At 192kHz stereo:
- buf_size: 1,152,000 samples = 9.2 MB
- limiter_buf_size: 80,640 samples = 0.6 MB
- Wasted: ~8.2 MB per filter instance

The bug was introduced when the limiter buffer was added but the
wrong size variable was used in av_malloc_array().
---
 libavfilter/af_loudnorm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
index 432b9710a5..00d0a145ae 100644
--- a/libavfilter/af_loudnorm.c
+++ b/libavfilter/af_loudnorm.c
@@ -774,7 +774,7 @@ static int config_input(AVFilterLink *inlink)
         return AVERROR(ENOMEM);
 
     s->limiter_buf_size = frame_size(inlink->sample_rate, 210) * 
inlink->ch_layout.nb_channels;
-    s->limiter_buf = av_malloc_array(s->buf_size, sizeof(*s->limiter_buf));
+    s->limiter_buf = av_malloc_array(s->limiter_buf_size, 
sizeof(*s->limiter_buf));
     if (!s->limiter_buf)
         return AVERROR(ENOMEM);
 
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to