public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [2.6 patch] isdn/gigaset/common.c: fix a memory leak
@ 2006-04-04 19:00 Adrian Bunk
  2006-04-05  9:39 ` Tilman Schmidt
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Bunk @ 2006-04-04 19:00 UTC (permalink / raw)
  To: hjlipp, tilman; +Cc: gigaset307x-common, kkeil, isdn4linux, linux-kernel

This patch fixes a memory leak spotted by the Coverity checker
if (!try_module_get(owner)).

Signed-off-by: Adrian Bunk <bunk@stusta.de>

---

 drivers/isdn/gigaset/common.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

--- linux-2.6.17-rc1-mm1-full/drivers/isdn/gigaset/common.c.old	2006-04-04 19:45:19.000000000 +0200
+++ linux-2.6.17-rc1-mm1-full/drivers/isdn/gigaset/common.c	2006-04-04 19:51:23.000000000 +0200
@@ -1110,8 +1110,9 @@ struct gigaset_driver *gigaset_initdrive
 	drv = kmalloc(sizeof *drv, GFP_KERNEL);
 	if (!drv)
 		return NULL;
+
 	if (!try_module_get(owner))
-		return NULL;
+		goto out1;
 
 	drv->cs = NULL;
 	drv->have_tty = 0;
@@ -1125,10 +1126,11 @@ struct gigaset_driver *gigaset_initdrive
 
 	drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
 	if (!drv->cs)
-		goto out1;
+		goto out2;
+
 	drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
 	if (!drv->flags)
-		goto out2;
+		goto out3;
 
 	for (i = 0; i < minors; ++i) {
 		drv->flags[i] = 0;
@@ -1145,11 +1147,12 @@ struct gigaset_driver *gigaset_initdrive
 
 	return drv;
 
-out2:
+out3:
 	kfree(drv->cs);
+out2:
+	module_put(owner);
 out1:
 	kfree(drv);
-	module_put(owner);
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(gigaset_initdriver);


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

* Re: [2.6 patch] isdn/gigaset/common.c: fix a memory leak
  2006-04-04 19:00 [2.6 patch] isdn/gigaset/common.c: fix a memory leak Adrian Bunk
@ 2006-04-05  9:39 ` Tilman Schmidt
  0 siblings, 0 replies; 2+ messages in thread
From: Tilman Schmidt @ 2006-04-05  9:39 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: hjlipp, gigaset307x-common, kkeil, isdn4linux, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1626 bytes --]

Adrian Bunk wrote:

> This patch fixes a memory leak spotted by the Coverity checker
> if (!try_module_get(owner)).

Good catch. Thanks.

> Signed-off-by: Adrian Bunk <bunk@stusta.de>

Acked-by: Tilman Schmidt <tilman@imap.cc>

>
> ---
>
>  drivers/isdn/gigaset/common.c |   13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
>
> --- linux-2.6.17-rc1-mm1-full/drivers/isdn/gigaset/common.c.old	2006-04-04 19:45:19.000000000 +0200
> +++ linux-2.6.17-rc1-mm1-full/drivers/isdn/gigaset/common.c	2006-04-04 19:51:23.000000000 +0200
> @@ -1110,8 +1110,9 @@ struct gigaset_driver *gigaset_initdrive
>  	drv = kmalloc(sizeof *drv, GFP_KERNEL);
>  	if (!drv)
>  		return NULL;
> +
>  	if (!try_module_get(owner))
> -		return NULL;
> +		goto out1;
>
>  	drv->cs = NULL;
>  	drv->have_tty = 0;
> @@ -1125,10 +1126,11 @@ struct gigaset_driver *gigaset_initdrive
>
>  	drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
>  	if (!drv->cs)
> -		goto out1;
> +		goto out2;
> +
>  	drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
>  	if (!drv->flags)
> -		goto out2;
> +		goto out3;
>
>  	for (i = 0; i < minors; ++i) {
>  		drv->flags[i] = 0;
> @@ -1145,11 +1147,12 @@ struct gigaset_driver *gigaset_initdrive
>
>  	return drv;
>
> -out2:
> +out3:
>  	kfree(drv->cs);
> +out2:
> +	module_put(owner);
>  out1:
>  	kfree(drv);
> -	module_put(owner);
>  	return NULL;
>  }
>  EXPORT_SYMBOL_GPL(gigaset_initdriver);
>


--
Tilman Schmidt                    E-Mail: tilman@imap.cc
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

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

end of thread, other threads:[~2006-04-05  9:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-04 19:00 [2.6 patch] isdn/gigaset/common.c: fix a memory leak Adrian Bunk
2006-04-05  9:39 ` Tilman Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox