linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rahul Jain <rahul.jain@samsung.com>
To: johannes@sipsolutions.net
Cc: linux-wireless@vger.kernel.org,
	Amit Khatri <amit.khatri@samsung.com>,
	Rahul Jain <rahul.jain@samsung.com>
Subject: [PATCH] iw:Fix memory leak if nla_put fails
Date: Fri, 27 Nov 2015 15:07:21 +0530	[thread overview]
Message-ID: <1448617041-20120-1-git-send-email-rahul.jain@samsung.com> (raw)

From: Amit Khatri <amit.khatri@samsung.com>

Avoid memory leak because of nla_put_failure

Signed-off-by: Rahul Jain <rahul.jain@samsung.com>
Signed-off-by: Amit Khatri <amit.khatri@samsung.com>
---
 coalesce.c |  7 ++++++-
 wowlan.c   | 33 +++++++++++++++++++++++++++------
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/coalesce.c b/coalesce.c
index 36dcaef..822da4f 100644
--- a/coalesce.c
+++ b/coalesce.c
@@ -124,7 +124,8 @@ static int handle_coalesce_enable(struct nl80211_state *state,
 					nla_nest_end(msg, nl_pat);
 					free(mask);
 					free(pat);
-
+					pat = NULL;
+					mask = NULL;
 					if (!next_pat)
 						break;
 					cur_pat = next_pat;
@@ -155,6 +156,10 @@ static int handle_coalesce_enable(struct nl80211_state *state,
 		err = 1;
 	goto close;
 nla_put_failure:
+	if (pat)
+		free(pat);
+	if (mask)
+		free(mask);
 	err = -ENOBUFS;
 close:
 	fclose(f);
diff --git a/wowlan.c b/wowlan.c
index e0cf316..c674e2c 100644
--- a/wowlan.c
+++ b/wowlan.c
@@ -89,7 +89,11 @@ static int wowlan_parse_tcp_file(struct nl_msg *msg, const char *fn)
 
 			if (!pkt)
 				goto close;
-			NLA_PUT(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, len, pkt);
+			if (nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, len,
+				pkt) < 0) {
+				free(pkt);
+				goto nla_put_failure;
+			}
 			free(pkt);
 		} else if (strncmp(buf, "data.interval=", 14) == 0) {
 			NLA_PUT_U32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
@@ -97,13 +101,24 @@ static int wowlan_parse_tcp_file(struct nl_msg *msg, const char *fn)
 		} else if (strncmp(buf, "wake=", 5) == 0) {
 			unsigned char *pat, *mask;
 			size_t patlen;
-
 			if (parse_hex_mask(buf + 5, &pat, &patlen, &mask))
 				goto close;
-			NLA_PUT(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
-				DIV_ROUND_UP(patlen, 8), mask);
-			NLA_PUT(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
-				patlen, pat);
+			if (nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
+				DIV_ROUND_UP(patlen, 8), mask) < 0) {
+				free(mask);
+				free(pat);
+				mask = NULL;
+				pat = NULL;
+				goto nla_put_failure;
+			}
+			if (nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
+				patlen, pat) < 0){
+				free(pat);
+				free(mask);
+				pat = NULL;
+				mask = NULL;
+				goto nla_put_failure;
+			}
 			free(mask);
 			free(pat);
 		} else if (strncmp(buf, "data.seq=", 9) == 0) {
@@ -300,6 +315,8 @@ static int handle_wowlan_enable(struct nl80211_state *state,
 			nla_nest_end(patterns, pattern);
 			free(mask);
 			free(pat);
+			pat = NULL;
+			mask = NULL;
 			break;
 		}
 		argv++;
@@ -313,6 +330,10 @@ static int handle_wowlan_enable(struct nl80211_state *state,
 	nla_nest_end(msg, wowlan);
 	err = 0;
  nla_put_failure:
+	if (pat)
+		free(pat);
+	if (mask)
+		free(mask);
 	nlmsg_free(patterns);
 	return err;
 }
-- 
1.9.1


             reply	other threads:[~2015-11-27  9:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-27  9:37 Rahul Jain [this message]
2016-01-06 11:11 ` [PATCH] iw:Fix memory leak if nla_put fails Johannes Berg
  -- strict thread matches above, loose matches on Subject: below --
2015-11-07 11:43 [PATCH] iw: Fix " Amit Khatri
2015-11-07 11:36 Amit Khatri
2015-10-23 22:33 Ola Olsson
2015-11-03 10:28 ` Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448617041-20120-1-git-send-email-rahul.jain@samsung.com \
    --to=rahul.jain@samsung.com \
    --cc=amit.khatri@samsung.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).