netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bridge: netfilter: fix a memory leak
@ 2010-08-20  5:03 Changli Gao
  2010-08-23  4:36 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Changli Gao @ 2010-08-20  5:03 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: David S. Miller, bridge, netdev, Changli Gao

nf_bridge_alloc() always reset the skb->nf_bridge, so we should always
put the old one. skb->nf_bridge->use is initialized in nf_bridge_alloc(),
so we don't need to initialize it again.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
---
 net/bridge/br_netfilter.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index 2c911c0..7fde554 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -159,11 +159,9 @@ static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb)
 	if (atomic_read(&nf_bridge->use) > 1) {
 		struct nf_bridge_info *tmp = nf_bridge_alloc(skb);
 
-		if (tmp) {
+		if (tmp)
 			memcpy(tmp, nf_bridge, sizeof(struct nf_bridge_info));
-			atomic_set(&tmp->use, 1);
-			nf_bridge_put(nf_bridge);
-		}
+		nf_bridge_put(nf_bridge);
 		nf_bridge = tmp;
 	}
 	return nf_bridge;

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

* Re: [PATCH] bridge: netfilter: fix a memory leak
  2010-08-20  5:03 [PATCH] bridge: netfilter: fix a memory leak Changli Gao
@ 2010-08-23  4:36 ` David Miller
  2010-08-23  4:40   ` Changli Gao
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2010-08-23  4:36 UTC (permalink / raw)
  To: xiaosuo; +Cc: shemminger, bridge, netdev

From: Changli Gao <xiaosuo@gmail.com>
Date: Fri, 20 Aug 2010 13:03:16 +0800

> nf_bridge_alloc() always reset the skb->nf_bridge, so we should always
> put the old one. skb->nf_bridge->use is initialized in nf_bridge_alloc(),
> so we don't need to initialize it again.
> 
> Signed-off-by: Changli Gao <xiaosuo@gmail.com>

We just memcpy()'d 'nf_bridge' to 'tmp', that why the ->use count is
going to be something other than '1'.  It now has the ->use count that
'nf_bridge' did.

And that is why we must explicitly do atomic_set() on 'tmp'.

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

* Re: [PATCH] bridge: netfilter: fix a memory leak
  2010-08-23  4:36 ` David Miller
@ 2010-08-23  4:40   ` Changli Gao
  0 siblings, 0 replies; 3+ messages in thread
From: Changli Gao @ 2010-08-23  4:40 UTC (permalink / raw)
  To: David Miller; +Cc: shemminger, bridge, netdev

On Mon, Aug 23, 2010 at 12:36 PM, David Miller <davem@davemloft.net> wrote:
> From: Changli Gao <xiaosuo@gmail.com>
> Date: Fri, 20 Aug 2010 13:03:16 +0800
>
>> nf_bridge_alloc() always reset the skb->nf_bridge, so we should always
>> put the old one. skb->nf_bridge->use is initialized in nf_bridge_alloc(),
>> so we don't need to initialize it again.
>>
>> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
>
> We just memcpy()'d 'nf_bridge' to 'tmp', that why the ->use count is
> going to be something other than '1'.  It now has the ->use count that
> 'nf_bridge' did.
>
> And that is why we must explicitly do atomic_set() on 'tmp'.
>

Oops, thanks. I'll post a update.


-- 
Regards,
Changli Gao(xiaosuo@gmail.com)

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-20  5:03 [PATCH] bridge: netfilter: fix a memory leak Changli Gao
2010-08-23  4:36 ` David Miller
2010-08-23  4:40   ` Changli Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).