mpls: fix mpls_net_init memory leak
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Mon, 31 Aug 2015 17:44:19 +0000 (10:44 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 31 Aug 2015 19:45:09 +0000 (12:45 -0700)
Fix a memory leak in the mpls netns init function in case of failure. If
register_net_sysctl fails then we need to free the ctl_table.

Fixes: 7720c01f3f59 ("mpls: Add a sysctl to control the size of the mpls label table")
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mpls/af_mpls.c

index 8c5707db53c5f6e33987b7215a4b3843c60cd610..bb185a28de9890d2f4b3c57d1ca7af7600f9b2aa 100644 (file)
@@ -1177,8 +1177,10 @@ static int mpls_net_init(struct net *net)
 
        table[0].data = net;
        net->mpls.ctl = register_net_sysctl(net, "net/mpls", table);
-       if (net->mpls.ctl == NULL)
+       if (net->mpls.ctl == NULL) {
+               kfree(table);
                return -ENOMEM;
+       }
 
        return 0;
 }