Skip to contentSkip to conversation

ALSA: trident: Fix a memory leak in snd_trident_create

PATCH In review Navid Emamdoost 2 participants 3 messages Jul 11, 2020 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: trident: Fix a memory leak in snd_trident_create

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")
---
 sound/pci/trident/trident_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
sound/pci/trident/trident_main.c +4 -1
index 6e50376163a2..e98c692f6aa9 100644
@@ -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++) {
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Navid Emamdoost

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

Quoted 27 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 sound/pci/trident/trident_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
sound/pci/trident/trident_main.c +4 -1
index 6e50376163a2..e98c692f6aa9 100644
@@ -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++) {
Signature · 1 line
2.17.1
#2 lore raw
Quoted 4 lines · Takashi Iwai
Quoted 1 line · Navid Emamdoost
Quoted 8 lines
Quoted 2 lines

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.

Quoted 33 lines

thanks,

Takashi

Quoted 27 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 sound/pci/trident/trident_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
sound/pci/trident/trident_main.c +4 -2
index 6e50376163a2..e98c692f6aa9 100644
@@ -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

Signature · 1 line
Navid.