diff mbox series

net-veth: Fix memleak in veth_newlink

Message ID 20201022054233.17326-1-dinghao.liu@zju.edu.cn
State New
Headers show
Series net-veth: Fix memleak in veth_newlink | expand

Commit Message

Dinghao Liu Oct. 22, 2020, 5:42 a.m. UTC
When rtnl_configure_link() fails, peer needs to be
freed just like when register_netdevice() fails.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/net/veth.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Jakub Kicinski Oct. 22, 2020, 4:12 p.m. UTC | #1
On Thu, 22 Oct 2020 13:42:33 +0800 Dinghao Liu wrote:
> When rtnl_configure_link() fails, peer needs to be
> freed just like when register_netdevice() fails.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>

Can you see this leak or are you just sending this based on your
reading of the code?

netdev should be freed by the core:

static void veth_setup(struct net_device *dev)                                  
{                                                                               
        ether_setup(dev);                                                       
                                                                                
	[...]                    
        dev->needs_free_netdev = true;    

> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index 8c737668008a..6c68094399cc 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -1405,8 +1405,6 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
>  	/* nothing to do */
>  err_configure_peer:
>  	unregister_netdevice(peer);
> -	return err;
> -
>  err_register_peer:
>  	free_netdev(peer);
>  	return err;
diff mbox series

Patch

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 8c737668008a..6c68094399cc 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1405,8 +1405,6 @@  static int veth_newlink(struct net *src_net, struct net_device *dev,
 	/* nothing to do */
 err_configure_peer:
 	unregister_netdevice(peer);
-	return err;
-
 err_register_peer:
 	free_netdev(peer);
 	return err;