[alsa-devel] [PATCH - Multiple plugins 0/4] 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.h...
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(-)
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.
Signed-off-by: Andre Guedes andre.guedes@intel.com --- a52/pcm_a52.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/a52/pcm_a52.c b/a52/pcm_a52.c index 29ce45f..e431fd0 100644 --- a/a52/pcm_a52.c +++ b/a52/pcm_a52.c @@ -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;
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.
Signed-off-by: Andre Guedes andre.guedes@intel.com --- jack/pcm_jack.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/jack/pcm_jack.c b/jack/pcm_jack.c index b39835e..6aaecac 100644 --- a/jack/pcm_jack.c +++ b/jack/pcm_jack.c @@ -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; }
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.
Signed-off-by: Andre Guedes andre.guedes@intel.com --- oss/pcm_oss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/oss/pcm_oss.c b/oss/pcm_oss.c index dadbb5b..8ab4fb0 100644 --- a/oss/pcm_oss.c +++ b/oss/pcm_oss.c @@ -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;
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.
Signed-off-by: Andre Guedes andre.guedes@intel.com --- usb_stream/pcm_usb_stream.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/usb_stream/pcm_usb_stream.c b/usb_stream/pcm_usb_stream.c index 94c83a7..eb4ca98 100644 --- a/usb_stream/pcm_usb_stream.c +++ b/usb_stream/pcm_usb_stream.c @@ -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; }
Hi,
On Sep 29 2018 06:27, Andre Guedes wrote:
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.h...
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(-)
I've reviewed all of the above patches.
Reviewed-by: Takashi Sakamoto o-takashi@sakamocchi.jp
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
On Fri, 28 Sep 2018 23:27:23 +0200, Andre Guedes wrote:
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.h...
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
participants (3)
-
Andre Guedes
-
Takashi Iwai
-
Takashi Sakamoto