diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2020-01-08 08:39:48 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2020-01-08 16:03:35 -0800 |
commit | a6dd04807ce4d7b71920d996e6b84fa3733a1bfd (patch) | |
tree | 346e3f8e74ce2e868ea5ae0b317512a26cb347af /net/ethtool | |
parent | 78b6d073bc0101f9147845ba868d9d2e6189f990 (diff) |
ethtool: fix a memory leak in ethnl_default_start()
If ethnl_default_parse() fails then we need to free a couple
memory allocations before returning.
Fixes: 728480f12442 ("ethtool: default handlers for GET requests")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ethtool')
-rw-r--r-- | net/ethtool/netlink.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 4ca96c7b86b3..5d16436498ac 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -472,8 +472,8 @@ static int ethnl_default_start(struct netlink_callback *cb) return -ENOMEM; reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); if (!reply_data) { - kfree(req_info); - return -ENOMEM; + ret = -ENOMEM; + goto free_req_info; } ret = ethnl_default_parse(req_info, cb->nlh, sock_net(cb->skb->sk), ops, @@ -487,7 +487,7 @@ static int ethnl_default_start(struct netlink_callback *cb) req_info->dev = NULL; } if (ret < 0) - return ret; + goto free_reply_data; ctx->ops = ops; ctx->req_info = req_info; @@ -496,6 +496,13 @@ static int ethnl_default_start(struct netlink_callback *cb) ctx->pos_idx = 0; return 0; + +free_reply_data: + kfree(reply_data); +free_req_info: + kfree(req_info); + + return ret; } /* default ->done() handler for GET requests */ |