]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm_meter: fix dsd_states leak and widen s16 DSD smoothing cap
authorJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 20:53:33 +0000 (21:53 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 20:58:01 +0000 (21:58 +0100)
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 <perex@perex.cz>
src/pcm/pcm_meter.c

index 8a945097e8719cb53b3b704ebd90cd9d353678de..bfced6274cc14792d43003bce048f8424f320883 100644 (file)
@@ -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;
        }