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: 728480f124 ("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>
Signed-off-by: hongrongxuan <hongrongxuan@huawei.com>
This commit is contained in:
Dan Carpenter 2020-01-08 08:39:48 +03:00 committed by Jianping Liu
parent 10ecad85a7
commit 38b7ba2793
1 changed files with 10 additions and 3 deletions

View File

@ -474,8 +474,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,
@ -489,7 +489,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;
@ -498,6 +498,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 */