[PATCH] net/ncsi: prevent memory leak in ncsi_rsp_handler_gc

Navid Emamdoost
2019-09-25T22:05:25Z

In ncsi_rsp_handler_gc if allocation for nc->vlan_filter.vids fails the
allocated memory for nc->mac_filter.addrs should be released.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
net/ncsi/ncsi-rsp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index d5611f04926d..f3f7c3772994 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -800,8 +800,10 @@ static int ncsi_rsp_handler_gc(struct ncsi_request *nr)
nc->vlan_filter.vids = kcalloc(rsp->vlan_cnt,
sizeof(*nc->vlan_filter.vids),
GFP_ATOMIC);
- if (!nc->vlan_filter.vids)
+ if (!nc->vlan_filter.vids) {
+ kfree(nc->mac_filter.addrs);
return -ENOMEM;
+ }
/* Set VLAN filters active so they are cleared in the first
* configuration state
*/
--
2.17.1