Skip to contentSkip to conversation

Fix leaks on multiple plugins

PATCH Applied Andre Guedes 3 participants 7 messages Sep 28, 2018 – Oct 2, 2018

lore
Share & tools
lore
#0 lore raw

cover Fix leaks on multiple plugins

Hi all,

While I was working on AAF plugin RFC v2 series [1], I spotted several leaks in some plugins when handling *_hw_constraint() error cases. This series fixes these issues.

Regards,

Andre

[1] http://mailman.alsa-project.org/pipermail/alsa-devel/2018-September/140290.html

Andre Guedes (4):
a52: Fix leaks when a52_set_hw_constraint() fails
jack: Fix leaks when jack_set_hw_constraint() fails
oss: Fix leaks when oss_hw_constraint() fails
usb_stream: Fix leaks when us_set_hw_constraint() fails

 a52/pcm_a52.c               | 2 +-
 jack/pcm_jack.c             | 1 +
 oss/pcm_oss.c               | 2 +-
 usb_stream/pcm_usb_stream.c | 1 +
 4 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.14.4
#1 lore raw

PATCH 1/4 a52: Fix leaks when a52_set_hw_constraint() fails

If a52_set_hw_constraint() returns error, we leak 'rec' and 'rec->slave'. This patch fixes the issue by jumping to 'error' label where the proper clean up is already done.

---
 a52/pcm_a52.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
a52/pcm_a52.c +1 -1
index 29ce45f..e431fd0 100644
@@ -978,7 +978,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(a52)
 
 	if ((err = a52_set_hw_constraint(rec)) < 0) {
 		snd_pcm_ioplug_delete(&rec->io);
-		return err;
+		goto error;
 	}
 
 	*pcmp = rec->io.pcm;
Signature · 1 line
2.14.4
#2 lore raw

PATCH 2/4 jack: Fix leaks when jack_set_hw_constraint() fails

In reply to Andre Guedes

If jack_set_hw_constraint() returns error, we leak the 'jack' object and all the resources referenced by it. This patch fixes the issue by calling snd_pcm_jack_free() before returning.

---
 jack/pcm_jack.c | 1 +
 1 file changed, 1 insertion(+)
jack/pcm_jack.c +1 -0
index b39835e..6aaecac 100644
@@ -538,6 +538,7 @@ static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name,
 	err = jack_set_hw_constraint(jack);
 	if (err < 0) {
 		snd_pcm_ioplug_delete(&jack->io);
+		snd_pcm_jack_free(jack);
 		return err;
 	}
 
Signature · 1 line
2.14.4
#3 lore raw

PATCH 3/4 oss: Fix leaks when oss_hw_constraint() fails

In reply to Andre Guedes

If oss_hw_constraint() returns error, we leak 'oss' object and all the resources referenced by it. This patch fixes the issue by jumping to 'error' label where the proper clean up is already done.

---
 oss/pcm_oss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
oss/pcm_oss.c +1 -1
index dadbb5b..8ab4fb0 100644
@@ -413,7 +413,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(oss)
 
 	if ((err = oss_hw_constraint(oss)) < 0) {
 		snd_pcm_ioplug_delete(&oss->io);
-		return err;
+		goto error;
 	}
 
 	*pcmp = oss->io.pcm;
Signature · 1 line
2.14.4
#4 lore raw

PATCH 4/4 usb_stream: Fix leaks when us_set_hw_constraint() fails

In reply to Andre Guedes

If us_set_hw_constraint() returns error, we leak the 'us' object and all the resources referenced by it. This patch fixes the issue by calling us_free() before returning.

---
 usb_stream/pcm_usb_stream.c | 1 +
 1 file changed, 1 insertion(+)
usb_stream/pcm_usb_stream.c +1 -0
index 94c83a7..eb4ca98 100644
@@ -455,6 +455,7 @@ static int snd_pcm_us_open(snd_pcm_t **pcmp, const char *name,
 	err = us_set_hw_constraint(us);
 	if (err < 0) {
 		snd_pcm_ioplug_delete(&us->io);
+		us_free(us);
 		return err;
 	}
 
Signature · 1 line
2.14.4
Reviewed-by on the v1 series
#5 lore raw
In reply to Andre Guedes

Hi,

Quoted 16 lines · Andre Guedes

While I was working on AAF plugin RFC v2 series [1], I spotted several leaks in some plugins when handling *_hw_constraint() error cases. This series fixes these issues.

Regards,

Andre

[1] http://mailman.alsa-project.org/pipermail/alsa-devel/2018-September/140290.html

Andre Guedes (4):
a52: Fix leaks when a52_set_hw_constraint() fails
jack: Fix leaks when jack_set_hw_constraint() fails
oss: Fix leaks when oss_hw_constraint() fails
usb_stream: Fix leaks when us_set_hw_constraint() fails

Quoted 5 lines
  a52/pcm_a52.c               | 2 +-
  jack/pcm_jack.c             | 1 +
  oss/pcm_oss.c               | 2 +-
  usb_stream/pcm_usb_stream.c | 1 +
  4 files changed, 4 insertions(+), 2 deletions(-)

I've reviewed all of the above patches.

I think it better for the plugins to use goto statement to aggregate error paths for releasing allocated objects but this is just for code cleanups.

Regards

Takashi Sakamoto

Applied
#6 lore raw
In reply to Andre Guedes
Quoted 11 lines · Andre Guedes

Hi all,

While I was working on AAF plugin RFC v2 series [1], I spotted several leaks in some plugins when handling *_hw_constraint() error cases. This series fixes these issues.

Regards,

Andre

Quoted 7 lines

[1] http://mailman.alsa-project.org/pipermail/alsa-devel/2018-September/140290.html

Andre Guedes (4):
a52: Fix leaks when a52_set_hw_constraint() fails
jack: Fix leaks when jack_set_hw_constraint() fails
oss: Fix leaks when oss_hw_constraint() fails
usb_stream: Fix leaks when us_set_hw_constraint() fails

Applied all four patches now. Thanks.

Takashi