Re: [PATCH] ALSA: hda/core: fix memory leak in snd_hdac_bus_alloc_stream_pages()

From: Zhao Dongdong

Date: Mon Jul 06 2026 - 07:12:05 EST


On Mon, 06 Jul 2026 10:11:56 +0200, Takashi Iwai <tiwai@xxxxxxx> wrote:
>
> On Mon, 06 Jul 2026 09:41:10 +0200,
> Zhao Dongdong wrote:
> >
> > From: Zhao Dongdong <zhaodongdong@xxxxxxxxxx>
> >
> > In snd_hdac_bus_alloc_stream_pages(), there are three memory leak paths:
> >
> > 1. If snd_dma_alloc_pages() for the BDL fails at stream i, the
> > previously allocated BDL DMA buffers (0..i-1) are not freed.
> >
> > 2. If snd_dma_alloc_pages() for the position buffer fails, all
> > previously allocated BDL DMA buffers are leaked.
> >
> > 3. If snd_dma_alloc_pages() for the ring buffer fails, all
> > previously allocated BDL DMA buffers and the position buffer
> > are leaked.
> >
> > Add proper error cleanup: free buffers that have been allocated
> > before each failure point.
> >
> > Fixes: b2660d1ebde1 ("ALSA: hda: Move HD-audio core stuff into sound/hda/core")
> > Signed-off-by: Zhao Dongdong <zhaodongdong@xxxxxxxxxx>
>
> They don't actually leak, as those are supposed to be released by
> callers (via snd_hdac_bus_free_stream_pages() call at destructor).
> That is, it's no bug, per se.
>
> Of course, it won't be bad to clean up in the function itself, which
> is more self-contained and safer. But please rephrase the patch
> subject and description, so that it won't be taken as a security issue
> incorrectly.
>
>
> thanks,
>
> Takashi

Thanks for your review.
You are right that snd_hdac_bus_alloc_stream_pages and snd_hdac_bus_free_stream_pages
are paired, so the extra free call is unnecessary, please ignore this patch.


--
Regards,
Zhao Dongdong