linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: trident: Fix a memory leak in snd_trident_create
@ 2020-07-11  7:08 Navid Emamdoost
  2020-07-11  9:04 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Navid Emamdoost @ 2020-07-11  7:08 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai, Navid Emamdoost, alsa-devel, linux-kernel
  Cc: emamd001, kjlu, smccaman

In the implementation of snd_trident_create(), the allocated trident is
leaked if snd_trident_mixer() fails. Release via snd_trident_free().

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 sound/pci/trident/trident_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index 6e50376163a2..e98c692f6aa9 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -3582,8 +3582,11 @@ int snd_trident_create(struct snd_card *card,
 		return err;
 	}
 
-	if ((err = snd_trident_mixer(trident, pcm_spdif_device)) < 0)
+	err = snd_trident_mixer(trident, pcm_spdif_device);
+	if (err < 0) {
+		snd_trident_free(trident);
 		return err;
+	}
 	
 	/* initialise synth voices */
 	for (i = 0; i < 64; i++) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: trident: Fix a memory leak in snd_trident_create
  2020-07-11  7:08 [PATCH] ALSA: trident: Fix a memory leak in snd_trident_create Navid Emamdoost
@ 2020-07-11  9:04 ` Takashi Iwai
  2020-07-11 18:16   ` Navid Emamdoost
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2020-07-11  9:04 UTC (permalink / raw)
  To: Navid Emamdoost
  Cc: Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel,
	emamd001, kjlu, smccaman

On Sat, 11 Jul 2020 09:08:30 +0200,
Navid Emamdoost wrote:
> 
> In the implementation of snd_trident_create(), the allocated trident is
> leaked if snd_trident_mixer() fails. Release via snd_trident_free().

No, this patch would result in double-free.

The manual release of trident object isn't needed once after it gets
added via snd_device_new().  Then it'll be automatically released at
the error path (via snd_trident_dev_free()).


thanks,

Takashi

> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  sound/pci/trident/trident_main.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
> index 6e50376163a2..e98c692f6aa9 100644
> --- a/sound/pci/trident/trident_main.c
> +++ b/sound/pci/trident/trident_main.c
> @@ -3582,8 +3582,11 @@ int snd_trident_create(struct snd_card *card,
>  		return err;
>  	}
>  
> -	if ((err = snd_trident_mixer(trident, pcm_spdif_device)) < 0)
> +	err = snd_trident_mixer(trident, pcm_spdif_device);
> +	if (err < 0) {
> +		snd_trident_free(trident);
>  		return err;
> +	}
>  	
>  	/* initialise synth voices */
>  	for (i = 0; i < 64; i++) {
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: trident: Fix a memory leak in snd_trident_create
  2020-07-11  9:04 ` Takashi Iwai
@ 2020-07-11 18:16   ` Navid Emamdoost
  0 siblings, 0 replies; 3+ messages in thread
From: Navid Emamdoost @ 2020-07-11 18:16 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, Takashi Iwai, alsa-devel, LKML, Navid Emamdoost,
	Kangjie Lu, Stephen McCamant

On Sat, Jul 11, 2020 at 4:04 AM Takashi Iwai <tiwai@suse.de> wrote:
>
> On Sat, 11 Jul 2020 09:08:30 +0200,
> Navid Emamdoost wrote:
> >
> > In the implementation of snd_trident_create(), the allocated trident is
> > leaked if snd_trident_mixer() fails. Release via snd_trident_free().
>
> No, this patch would result in double-free.
>
> The manual release of trident object isn't needed once after it gets
> added via snd_device_new().  Then it'll be automatically released at
> the error path (via snd_trident_dev_free()).

Thanks for the clarification.

>
>
> thanks,
>
> Takashi
>
> >
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> > ---
> >  sound/pci/trident/trident_main.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
> > index 6e50376163a2..e98c692f6aa9 100644
> > --- a/sound/pci/trident/trident_main.c
> > +++ b/sound/pci/trident/trident_main.c
> > @@ -3582,8 +3582,11 @@ int snd_trident_create(struct snd_card *card,
> >               return err;
> >       }
> >
> > -     if ((err = snd_trident_mixer(trident, pcm_spdif_device)) < 0)
> > +     err = snd_trident_mixer(trident, pcm_spdif_device);
> > +     if (err < 0) {
> > +             snd_trident_free(trident);
> >               return err;
> > +     }
> >
> >       /* initialise synth voices */
> >       for (i = 0; i < 64; i++) {
> > --
> > 2.17.1
> >



-- 
Navid.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-11 18:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-11  7:08 [PATCH] ALSA: trident: Fix a memory leak in snd_trident_create Navid Emamdoost
2020-07-11  9:04 ` Takashi Iwai
2020-07-11 18:16   ` Navid Emamdoost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).