[alsa-devel] [PATCH] ALSA: pcm: Fix memory leak at closing a stream without hw_free

Pierre-Louis Bossart pierre-louis.bossart at linux.intel.com
Thu Feb 13 16:24:43 CET 2020


> From: Takashi Iwai <tiwai at suse.de>
> Subject: [PATCH] ALSA: pcm: Fix double hw_free calls
> 
> The commit 66f2d19f8116 ("ALSA: pcm: Fix memory leak at closing a
> stream without hw_free") tried to fix the regression wrt the missing
> hw_free call at closing without SNDRV_PCM_IOCTL_HW_FREE ioctl.
> However, the code change dropped mistakenly the state check, resulting
> in calling hw_free twice when SNDRV_PCM_IOCTL_HW_FRE got called
> beforehand.  For most drivers, this is almost harmless, but the
> drivers like SOF show another regression now.
> 
> This patch adds the state condition check before calling do_hw_free()
> at releasing the stream for avoiding the double hw_free calls.
> 
> Fixes: 66f2d19f8116 ("ALSA: pcm: Fix memory leak at closing a stream without hw_free")
> Reported-by: Bard Liao <yung-chuan.liao at linux.intel.com>
> Reported-by: Pierre-Louis Bossart <pierre-louis.bossart at linux.intel.com>
> Cc: <stable at vger.kernel.org>
> Signed-off-by: Takashi Iwai <tiwai at suse.de>

Tested-by: Pierre-Louis Bossart <pierre-louis.bossart at linux.intel.com>

Thanks Takashi!

> ---
>   sound/core/pcm_native.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 336406bcb59e..d5443eeb8b63 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -2594,7 +2594,8 @@ void snd_pcm_release_substream(struct snd_pcm_substream *substream)
>   
>   	snd_pcm_drop(substream);
>   	if (substream->hw_opened) {
> -		do_hw_free(substream);
> +		if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
> +			do_hw_free(substream);
>   		substream->ops->close(substream);
>   		substream->hw_opened = 0;
>   	}
> 


More information about the Alsa-devel mailing list