All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] drivers/net/irda: Eliminate memory leak
@ 2010-08-24 14:38 ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2010-08-24 14:38 UTC (permalink / raw)
  To: Samuel Ortiz, netdev, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

dev_alloc_skb allocates some memory, so that memory should be freed before
leaving the function in an error case.

Corrected some typos in a nearby comment as well.

A simplified version of the semantic match that finds this problem is:
(http://coccinelle.lip6.fr/)

// <smpl>
@r exists@
local idexpression x;
expression E;
identifier f1;
iterator I;
@@

x = dev_alloc_skb(...);
<... when != x
     when != true (x == NULL || ...)
     when != if (...) { <+...x...+> }
     when != I (...) { <+...x...+> }
(
 x == NULL
|
 x == E
|
 x->f1
)
...>
* return ...;
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/net/irda/via-ircc.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/irda/via-ircc.c b/drivers/net/irda/via-ircc.c
index b0a6cd8..67c0ad4 100644
--- a/drivers/net/irda/via-ircc.c
+++ b/drivers/net/irda/via-ircc.c
@@ -1182,12 +1182,13 @@ F01_E */
 
 		skb = dev_alloc_skb(len + 1 - 4);
 		/*
-		 * if frame size,data ptr,or skb ptr are wrong ,the get next
+		 * if frame size, data ptr, or skb ptr are wrong, then get next
 		 * entry.
 		 */
 		if ((skb == NULL) || (skb->data == NULL) ||
 		    (self->rx_buff.data == NULL) || (len < 6)) {
 			self->netdev->stats.rx_dropped++;
+			kfree_skb(skb);
 			return TRUE;
 		}
 		skb_reserve(skb, 1);

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

* [PATCH 1/5] drivers/net/irda: Eliminate memory leak
@ 2010-08-24 14:38 ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2010-08-24 14:38 UTC (permalink / raw)
  To: Samuel Ortiz, netdev, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

dev_alloc_skb allocates some memory, so that memory should be freed before
leaving the function in an error case.

Corrected some typos in a nearby comment as well.

A simplified version of the semantic match that finds this problem is:
(http://coccinelle.lip6.fr/)

// <smpl>
@r exists@
local idexpression x;
expression E;
identifier f1;
iterator I;
@@

x = dev_alloc_skb(...);
<... when != x
     when != true (x = NULL || ...)
     when != if (...) { <+...x...+> }
     when != I (...) { <+...x...+> }
(
 x = NULL
|
 x = E
|
 x->f1
)
...>
* return ...;
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/net/irda/via-ircc.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/irda/via-ircc.c b/drivers/net/irda/via-ircc.c
index b0a6cd8..67c0ad4 100644
--- a/drivers/net/irda/via-ircc.c
+++ b/drivers/net/irda/via-ircc.c
@@ -1182,12 +1182,13 @@ F01_E */
 
 		skb = dev_alloc_skb(len + 1 - 4);
 		/*
-		 * if frame size,data ptr,or skb ptr are wrong ,the get next
+		 * if frame size, data ptr, or skb ptr are wrong, then get next
 		 * entry.
 		 */
 		if ((skb = NULL) || (skb->data = NULL) ||
 		    (self->rx_buff.data = NULL) || (len < 6)) {
 			self->netdev->stats.rx_dropped++;
+			kfree_skb(skb);
 			return TRUE;
 		}
 		skb_reserve(skb, 1);

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

* Re: [PATCH 1/5] drivers/net/irda: Eliminate memory leak
  2010-08-24 14:38 ` Julia Lawall
@ 2010-08-25 23:37   ` David Miller
  -1 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2010-08-25 23:37 UTC (permalink / raw)
  To: julia; +Cc: samuel, netdev, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>
Date: Tue, 24 Aug 2010 16:38:33 +0200 (CEST)

> From: Julia Lawall <julia@diku.dk>
> 
> dev_alloc_skb allocates some memory, so that memory should be freed before
> leaving the function in an error case.
> 
> Corrected some typos in a nearby comment as well.
> 
> A simplified version of the semantic match that finds this problem is:
> (http://coccinelle.lip6.fr/)
 ...
> Signed-off-by: Julia Lawall <julia@diku.dk>

Applied.

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

* Re: [PATCH 1/5] drivers/net/irda: Eliminate memory leak
@ 2010-08-25 23:37   ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2010-08-25 23:37 UTC (permalink / raw)
  To: julia; +Cc: samuel, netdev, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>
Date: Tue, 24 Aug 2010 16:38:33 +0200 (CEST)

> From: Julia Lawall <julia@diku.dk>
> 
> dev_alloc_skb allocates some memory, so that memory should be freed before
> leaving the function in an error case.
> 
> Corrected some typos in a nearby comment as well.
> 
> A simplified version of the semantic match that finds this problem is:
> (http://coccinelle.lip6.fr/)
 ...
> Signed-off-by: Julia Lawall <julia@diku.dk>

Applied.

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

* Re: [PATCH 1/5] drivers/net/irda: Eliminate memory leak
       [not found] ` <1282776100-21671-2-git-send-email-julia@diku.dk>
@ 2010-08-25 21:57   ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2010-08-25 21:57 UTC (permalink / raw)
  To: Samuel Ortiz; +Cc: netdev

Hi all,

I'm really sorry to have spammed your mailbox with my send-email 
experiments...

julia

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

end of thread, other threads:[~2010-08-25 23:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-24 14:38 [PATCH 1/5] drivers/net/irda: Eliminate memory leak Julia Lawall
2010-08-24 14:38 ` Julia Lawall
2010-08-25 23:37 ` David Miller
2010-08-25 23:37   ` David Miller
     [not found] <1282776100-21671-1-git-send-email-julia@diku.dk>
     [not found] ` <1282776100-21671-2-git-send-email-julia@diku.dk>
2010-08-25 21:57   ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.