[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <d6ef9cecae9d567a2c4dac8dcb550f2a190d5dc3.1493699451.git.gfree.wind@foxmail.com>
Date: Tue, 2 May 2017 14:59:39 +0800
From: gfree.wind@...mail.com
To: davem@...emloft.net, jiri@...nulli.us, mareklindner@...mailbox.ch,
sw@...onwunderlich.de, a@...table.cc, kuznet@....inr.ac.ru,
jmorris@...ei.org, yoshfuji@...ux-ipv6.org, kaber@...sh.net,
steffen.klassert@...unet.com, herbert@...dor.apana.org.au,
netdev@...r.kernel.org
Cc: Gao Feng <gfree.wind@...mail.com>
Subject: [PATCH net v4 07/12] ip6_tunnel: Fix one possbile memleak when fail to register_netdevice
From: Gao Feng <gfree.wind@...mail.com>
The ip6_tunnel allocates some resources in its ndo_init func, and
free some of them in its destructor func. Then there is one memleak
that some errors happen after register_netdevice invokes the ndo_init
callback. Because only the ndo_uninit callback is invoked in the error
handler of register_netdevice, but destructor not.
Now create one new func ip6_tnl_destructor_free to free the mem in
the destructor, and ndo_uninit func also invokes it when fail to
register the ip6_tunnel device.
It's not only free all resources, but also follow the original desgin
that the resources are freed in the destructor normally after
register the device successfully.
Signed-off-by: Gao Feng <gfree.wind@...mail.com>
---
net/ipv6/ip6_tunnel.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index a9692ec..7dcb234 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -247,13 +247,18 @@ static struct net_device_stats *ip6_get_stats(struct net_device *dev)
}
}
-static void ip6_dev_free(struct net_device *dev)
+static void ip6_tnl_destructor_free(struct net_device *dev)
{
struct ip6_tnl *t = netdev_priv(dev);
gro_cells_destroy(&t->gro_cells);
dst_cache_destroy(&t->dst_cache);
free_percpu(dev->tstats);
+}
+
+static void ip6_dev_free(struct net_device *dev)
+{
+ ip6_tnl_destructor_free(dev);
free_netdev(dev);
}
@@ -387,6 +392,10 @@ static struct ip6_tnl *ip6_tnl_locate(struct net *net,
ip6_tnl_unlink(ip6n, t);
dst_cache_reset(&t->dst_cache);
dev_put(dev);
+
+ /* dev is not registered, perform the free instead of destructor */
+ if (dev->reg_state == NETREG_UNINITIALIZED)
+ ip6_tnl_destructor_free(dev);
}
/**
--
1.9.1
Powered by blists - more mailing lists