From: mkver via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: mkver <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] avfilter/af_loudnorm: Avoid unchecked allocation (PR #21795)
Date: Thu, 19 Feb 2026 13:30:56 -0000
Message-ID: <177150785696.25.4521241190467802929@29965ddac10e> (raw)
PR #21795 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21795
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21795.patch
Also deduplicate printing json and summary output.
>From 4d5e74ac2f88aad895ff64329ee1384fd12ed2a7 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu, 19 Feb 2026 14:26:33 +0100
Subject: [PATCH] avfilter/af_loudnorm: Avoid unchecked allocation
Also deduplicate printing json and summary output.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavfilter/af_loudnorm.c | 36 ++++++++++--------------------------
1 file changed, 10 insertions(+), 26 deletions(-)
diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
index e9cc40baa6..17b819b185 100644
--- a/libavfilter/af_loudnorm.c
+++ b/libavfilter/af_loudnorm.c
@@ -20,7 +20,6 @@
/* http://k.ylo.ph/2016/04/04/loudnorm.html */
-#include "libavutil/avstring.h"
#include "libavutil/file_open.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
@@ -834,7 +833,6 @@ static av_cold void uninit(AVFilterContext *ctx)
double i_in, i_out, lra_in, lra_out, thresh_in, thresh_out, tp_in, tp_out;
int c;
FILE *stats_file = NULL;
- char *stats = NULL;
if (!s->r128_in || !s->r128_out)
goto end;
@@ -879,7 +877,9 @@ static av_cold void uninit(AVFilterContext *ctx)
break;
case JSON:
- stats = av_asprintf(
+ case SUMMARY: {
+ char stats[1024];
+ const char *const format = s->print_format == JSON ?
"{\n"
"\t\"input_i\" : \"%.2f\",\n"
"\t\"input_tp\" : \"%.2f\",\n"
@@ -891,25 +891,7 @@ static av_cold void uninit(AVFilterContext *ctx)
"\t\"output_thresh\" : \"%.2f\",\n"
"\t\"normalization_type\" : \"%s\",\n"
"\t\"target_offset\" : \"%.2f\"\n"
- "}\n",
- i_in,
- 20. * log10(tp_in),
- lra_in,
- thresh_in,
- i_out,
- 20. * log10(tp_out),
- lra_out,
- thresh_out,
- s->frame_type == LINEAR_MODE ? "linear" : "dynamic",
- s->target_i - i_out
- );
- av_log(ctx, AV_LOG_INFO, "\n%s", stats);
- if (stats_file)
- fprintf(stats_file, "%s", stats);
- break;
-
- case SUMMARY:
- stats = av_asprintf(
+ "}\n" :
"Input Integrated: %+6.1f LUFS\n"
"Input True Peak: %+6.1f dBTP\n"
"Input LRA: %6.1f LU\n"
@@ -921,7 +903,9 @@ static av_cold void uninit(AVFilterContext *ctx)
"Output Threshold: %+6.1f LUFS\n"
"\n"
"Normalization Type: %s\n"
- "Target Offset: %+6.1f LU\n",
+ "Target Offset: %+6.1f LU\n";
+
+ snprintf(stats, sizeof(stats), format,
i_in,
20. * log10(tp_in),
lra_in,
@@ -930,7 +914,8 @@ static av_cold void uninit(AVFilterContext *ctx)
20. * log10(tp_out),
lra_out,
thresh_out,
- s->frame_type == LINEAR_MODE ? "Linear" : "Dynamic",
+ s->frame_type == LINEAR_MODE ? (s->print_format == JSON ? "linear" : "Linear")
+ : (s->print_format == JSON ? "dynamic" : "Dynamic"),
s->target_i - i_out
);
av_log(ctx, AV_LOG_INFO, "\n%s", stats);
@@ -938,10 +923,9 @@ static av_cold void uninit(AVFilterContext *ctx)
fprintf(stats_file, "%s", stats);
break;
}
+ }
end:
- if (stats)
- av_free(stats);
if (stats_file && stats_file != stdout)
fclose(stats_file);
if (s->r128_in)
--
2.52.0
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2026-02-19 13:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=177150785696.25.4521241190467802929@29965ddac10e \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git