* [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak
@ 2014-01-27 22:29 xypron.glpk
2014-01-27 22:50 ` Greg KH
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: xypron.glpk @ 2014-01-27 22:29 UTC (permalink / raw)
To: devel
Cc: gregkh, ly80toro, ke42caxa, linux-usb, linux-kernel,
Heinrich Schuchardt
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
p is freed if NULL.
p is leaked if second calloc fails.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
drivers/staging/usbip/userspace/libsrc/names.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/usbip/userspace/libsrc/names.c b/drivers/staging/usbip/userspace/libsrc/names.c
index 3c8d28b..b2904e8 100644
--- a/drivers/staging/usbip/userspace/libsrc/names.c
+++ b/drivers/staging/usbip/userspace/libsrc/names.c
@@ -170,12 +170,12 @@ static void *my_malloc(size_t size)
p = calloc(1, sizeof(struct pool));
if (!p) {
- free(p);
return NULL;
}
p->mem = calloc(1, size);
if (!p->mem)
+ free(p);
return NULL;
p->next = pool_head;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak 2014-01-27 22:29 [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak xypron.glpk @ 2014-01-27 22:50 ` Greg KH 2014-01-27 23:02 ` Dan Carpenter 2014-01-27 22:52 ` Dan Carpenter 2014-01-27 23:52 ` Sergei Shtylyov 2 siblings, 1 reply; 8+ messages in thread From: Greg KH @ 2014-01-27 22:50 UTC (permalink / raw) To: xypron.glpk; +Cc: devel, linux-usb, ly80toro, linux-kernel, ke42caxa On Mon, Jan 27, 2014 at 11:29:48PM +0100, xypron.glpk@gmx.de wrote: > From: Heinrich Schuchardt <xypron.glpk@gmx.de> > > p is freed if NULL. Not a real problem, right? > p is leaked if second calloc fails. You just created a new bug in your "fix" :( Please run your patches through scripts/checkpatch.pl, odds are, it would have caught this error. greg k-h ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak 2014-01-27 22:50 ` Greg KH @ 2014-01-27 23:02 ` Dan Carpenter 2014-01-27 23:27 ` Greg KH 0 siblings, 1 reply; 8+ messages in thread From: Dan Carpenter @ 2014-01-27 23:02 UTC (permalink / raw) To: Greg KH; +Cc: xypron.glpk, devel, ke42caxa, linux-usb, ly80toro, linux-kernel On Mon, Jan 27, 2014 at 02:50:04PM -0800, Greg KH wrote: > On Mon, Jan 27, 2014 at 11:29:48PM +0100, xypron.glpk@gmx.de wrote: > > From: Heinrich Schuchardt <xypron.glpk@gmx.de> > > > > p is freed if NULL. > > Not a real problem, right? > > > p is leaked if second calloc fails. > > You just created a new bug in your "fix" :( > > Please run your patches through scripts/checkpatch.pl, odds are, it > would have caught this error. > Checkpatch doesn't catch the problems here. I thought it would have caught the style issue but apparently it only looks for extra curly braces when you run it in --file mode. Fengguang would hopefully have caught the missing curly braces bug with Coccinelle. regards, dan carpenter ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak 2014-01-27 23:02 ` Dan Carpenter @ 2014-01-27 23:27 ` Greg KH 2014-01-28 0:04 ` Dan Carpenter 0 siblings, 1 reply; 8+ messages in thread From: Greg KH @ 2014-01-27 23:27 UTC (permalink / raw) To: Dan Carpenter Cc: devel, xypron.glpk, linux-usb, ly80toro, linux-kernel, ke42caxa On Tue, Jan 28, 2014 at 02:02:12AM +0300, Dan Carpenter wrote: > On Mon, Jan 27, 2014 at 02:50:04PM -0800, Greg KH wrote: > > On Mon, Jan 27, 2014 at 11:29:48PM +0100, xypron.glpk@gmx.de wrote: > > > From: Heinrich Schuchardt <xypron.glpk@gmx.de> > > > > > > p is freed if NULL. > > > > Not a real problem, right? > > > > > p is leaked if second calloc fails. > > > > You just created a new bug in your "fix" :( > > > > Please run your patches through scripts/checkpatch.pl, odds are, it > > would have caught this error. > > > > Checkpatch doesn't catch the problems here. I thought it would have > caught the style issue but apparently it only looks for extra curly > braces when you run it in --file mode. Ah, that's good to know. > Fengguang would hopefully have caught the missing curly braces bug with > Coccinelle. Is Coccinelle run on the userspace .c code in the kernel? thanks, greg k-h ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak 2014-01-27 23:27 ` Greg KH @ 2014-01-28 0:04 ` Dan Carpenter 0 siblings, 0 replies; 8+ messages in thread From: Dan Carpenter @ 2014-01-28 0:04 UTC (permalink / raw) To: Greg KH Cc: devel, xypron.glpk, linux-usb, ly80toro, linux-kernel, ke42caxa, Fengguang Wu On Mon, Jan 27, 2014 at 03:27:36PM -0800, Greg KH wrote: > On Tue, Jan 28, 2014 at 02:02:12AM +0300, Dan Carpenter wrote: > > On Mon, Jan 27, 2014 at 02:50:04PM -0800, Greg KH wrote: > > > On Mon, Jan 27, 2014 at 11:29:48PM +0100, xypron.glpk@gmx.de wrote: > > > > From: Heinrich Schuchardt <xypron.glpk@gmx.de> > > > > > > > > p is freed if NULL. > > > > > > Not a real problem, right? > > > > > > > p is leaked if second calloc fails. > > > > > > You just created a new bug in your "fix" :( > > > > > > Please run your patches through scripts/checkpatch.pl, odds are, it > > > would have caught this error. > > > > > > > Checkpatch doesn't catch the problems here. I thought it would have > > caught the style issue but apparently it only looks for extra curly > > braces when you run it in --file mode. > > Ah, that's good to know. > > > Fengguang would hopefully have caught the missing curly braces bug with > > Coccinelle. > > Is Coccinelle run on the userspace .c code in the kernel? Hm... I'm not sure. Fengguang, do you know if we would have caught the missing curly braces in this patch? http://lkml.org/lkml/2014/1/27/460 regards, dan carpenter ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak 2014-01-27 22:29 [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak xypron.glpk 2014-01-27 22:50 ` Greg KH @ 2014-01-27 22:52 ` Dan Carpenter 2014-01-28 20:16 ` xypron.glpk 2014-01-27 23:52 ` Sergei Shtylyov 2 siblings, 1 reply; 8+ messages in thread From: Dan Carpenter @ 2014-01-27 22:52 UTC (permalink / raw) To: xypron.glpk; +Cc: devel, gregkh, linux-usb, ly80toro, linux-kernel, ke42caxa On Mon, Jan 27, 2014 at 11:29:48PM +0100, xypron.glpk@gmx.de wrote: > From: Heinrich Schuchardt <xypron.glpk@gmx.de> Fix your email account so we can get this automatically from your email. Currently the From header on your email is just: From: xypron.glpk@gmx.de without your name. > > p is freed if NULL. > p is leaked if second calloc fails. > > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > --- > drivers/staging/usbip/userspace/libsrc/names.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/usbip/userspace/libsrc/names.c b/drivers/staging/usbip/userspace/libsrc/names.c > index 3c8d28b..b2904e8 100644 > --- a/drivers/staging/usbip/userspace/libsrc/names.c > +++ b/drivers/staging/usbip/userspace/libsrc/names.c > @@ -170,12 +170,12 @@ static void *my_malloc(size_t size) > > p = calloc(1, sizeof(struct pool)); > if (!p) { > - free(p); > return NULL; > } Remove the curly braces from here since they are no longer needed. > > p->mem = calloc(1, size); > if (!p->mem) > + free(p); > return NULL; Add the curly braces here. They are required. regards, dan carpenter ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak 2014-01-27 22:52 ` Dan Carpenter @ 2014-01-28 20:16 ` xypron.glpk 0 siblings, 0 replies; 8+ messages in thread From: xypron.glpk @ 2014-01-28 20:16 UTC (permalink / raw) To: gregkh; +Cc: xypron.glpk, ly80toro, ke42caxa, linux-usb, linux-kernel From: Heinrich Schuchardt <xypron.glpk@gmx.de> revised patch p is freed if NULL. p is leaked if second calloc fails. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> --- drivers/staging/usbip/userspace/libsrc/names.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/usbip/userspace/libsrc/names.c b/drivers/staging/usbip/userspace/libsrc/names.c index 3c8d28b..81ff852 100644 --- a/drivers/staging/usbip/userspace/libsrc/names.c +++ b/drivers/staging/usbip/userspace/libsrc/names.c @@ -169,14 +169,14 @@ static void *my_malloc(size_t size) struct pool *p; p = calloc(1, sizeof(struct pool)); - if (!p) { - free(p); + if (!p) return NULL; - } p->mem = calloc(1, size); - if (!p->mem) + if (!p->mem) { + free(p); return NULL; + } p->next = pool_head; pool_head = p; -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak 2014-01-27 22:29 [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak xypron.glpk 2014-01-27 22:50 ` Greg KH 2014-01-27 22:52 ` Dan Carpenter @ 2014-01-27 23:52 ` Sergei Shtylyov 2 siblings, 0 replies; 8+ messages in thread From: Sergei Shtylyov @ 2014-01-27 23:52 UTC (permalink / raw) To: xypron.glpk, devel; +Cc: gregkh, ly80toro, ke42caxa, linux-usb, linux-kernel Hello. On 01/28/2014 01:29 AM, xypron.glpk@gmx.de wrote: > From: Heinrich Schuchardt <xypron.glpk@gmx.de> > p is freed if NULL. This is not an issue. > p is leaked if second calloc fails. > > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > --- > drivers/staging/usbip/userspace/libsrc/names.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/usbip/userspace/libsrc/names.c b/drivers/staging/usbip/userspace/libsrc/names.c > index 3c8d28b..b2904e8 100644 > --- a/drivers/staging/usbip/userspace/libsrc/names.c > +++ b/drivers/staging/usbip/userspace/libsrc/names.c > @@ -170,12 +170,12 @@ static void *my_malloc(size_t size) > > p = calloc(1, sizeof(struct pool)); > if (!p) { > - free(p); > return NULL; > } {} not needed anymore. > > p->mem = calloc(1, size); > if (!p->mem) > + free(p); > return NULL; How about {} around the *if* arm? WBR, Sergei ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-01-28 20:16 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-01-27 22:29 [PATCH 1/1] usbip/userspace/libsrc/names.c: memory leak xypron.glpk 2014-01-27 22:50 ` Greg KH 2014-01-27 23:02 ` Dan Carpenter 2014-01-27 23:27 ` Greg KH 2014-01-28 0:04 ` Dan Carpenter 2014-01-27 22:52 ` Dan Carpenter 2014-01-28 20:16 ` xypron.glpk 2014-01-27 23:52 ` Sergei Shtylyov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox