From 95207e71c04b75adf3abb72dd467fdf4c0b50038 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 30 Nov 2026 21:53:33 +0100 Subject: [PATCH] pcm_meter: fix dsd_states leak and widen s16 DSD smoothing cap Free dsd_states on the s16_enable OOM paths, and raise the dsd_shift cap to 12 so the smoothing window reaches ~0.25 ms at every DSD rate while staying inside the int32 EMA accumulator bound. Signed-off-by: Jaroslav Kysela --- src/pcm/pcm_meter.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pcm/pcm_meter.c b/src/pcm/pcm_meter.c index 8a945097..bfced627 100644 --- a/src/pcm/pcm_meter.c +++ b/src/pcm/pcm_meter.c @@ -1142,10 +1142,13 @@ static int s16_enable(snd_pcm_scope_t *scope) case SND_PCM_FORMAT_DSD_U32_BE: s16->dsd_bits = dsd_frame_bits(spcm->format); /* Smooth over about a quarter of a millisecond, taken from the - * rate so the behaviour is the same at every DSD rate. */ + * rate so the behaviour is the same at every DSD rate. The + * cap keeps the window below what overflows the int32 EMA + * accumulator (acc <= 65534 << shift); 12 covers DSD512 while + * staying far inside that bound. */ s16->dsd_shift = 1; while ((1U << (s16->dsd_shift + 1)) <= spcm->rate / 4000 && - s16->dsd_shift < 8) + s16->dsd_shift < 12) s16->dsd_shift++; idx = 0; break; @@ -1181,12 +1184,14 @@ static int s16_enable(snd_pcm_scope_t *scope) */ s16->buf = calloc(meter->buf_size * 2 * spcm->channels, 1); if (!s16->buf) { + free(s16->dsd_states); free(s16->adpcm_states); return -ENOMEM; } a = calloc(spcm->channels, sizeof(*a)); if (!a) { free(s16->buf); + free(s16->dsd_states); free(s16->adpcm_states); return -ENOMEM; } -- 2.52.0