Re: [PATCH] iw:Fix memory leak if nla_put fails
From: Johannes Berg <johannes@sipsolutions.net>
Date: 2016-01-06 11:11:03
On Fri, 2015-11-27 at 15:07 +0530, Rahul Jain wrote:
quoted hunk ↗ jump to hunk
@@ -124,7 +124,8 @@ static int handle_coalesce_enable(structnl80211_state *state, nla_nest_end(msg, nl_pat); free(mask); free(pat); - + pat = NULL; + mask = NULL;
I'd prefer to keep the blank line.
+ if (pat) + free(pat);
free(NULL) is valid and a no-op.
- 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;
+ }I don't understand - you also updated the nla_put_failure label to free it.
free(mask); free(pat);
seems like you need NULL here though. johannes