mwifiex: Fix mem leak in mwifiex_tm_cmd
authorYueHaibing <yuehaibing@huawei.com>
Tue, 12 Mar 2019 07:03:58 +0000 (15:03 +0800)
committerKalle Valo <kvalo@codeaurora.org>
Thu, 4 Apr 2019 10:18:42 +0000 (13:18 +0300)
'hostcmd' is alloced by kzalloc, should be freed before
leaving from the error handling cases, otherwise it will
cause mem leak.

Fixes: 3935ccc14d2c ("mwifiex: add cfg80211 testmode support")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/marvell/mwifiex/cfg80211.c

index c46f0a54a0c764ee563001aea96c30f8481fecb4..e582d9b3e50c27c32bdd59cfe142bf1c31921b37 100644 (file)
@@ -4082,16 +4082,20 @@ static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
 
                if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
                        dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
+                       kfree(hostcmd);
                        return -EFAULT;
                }
 
                /* process hostcmd response*/
                skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
-               if (!skb)
+               if (!skb) {
+                       kfree(hostcmd);
                        return -ENOMEM;
+               }
                err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
                              hostcmd->len, hostcmd->cmd);
                if (err) {
+                       kfree(hostcmd);
                        kfree_skb(skb);
                        return -EMSGSIZE;
                }