]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
net/netfilter/ipvs: Eliminate memory leak
authorJulia Lawall <julia@diku.dk>
Tue, 24 Aug 2010 04:39:49 +0000 (04:39 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 25 Aug 2010 23:36:50 +0000 (16:36 -0700)
__ip_vs_service_get and __ip_vs_svc_fwm_get increment a reference count, so
that reference count should be decremented before leaving the function in an
error case.

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 = __ip_vs_service_get(...);
<... 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>
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netfilter/ipvs/ip_vs_ctl.c

index 0f0c079c422a03f87616a1c1df76c0e387245a9e..53a88af225032943a2556ac37b0f1259d8eb78a6 100644 (file)
@@ -2155,7 +2155,7 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
        if (cmd != IP_VS_SO_SET_ADD
            && (svc == NULL || svc->protocol != usvc.protocol)) {
                ret = -ESRCH;
-               goto out_unlock;
+               goto out_drop_service;
        }
 
        switch (cmd) {
@@ -2189,6 +2189,7 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
                ret = -EINVAL;
        }
 
+out_drop_service:
        if (svc)
                ip_vs_service_put(svc);