Skip to content

Commit

Permalink
ieee802154: Don't leak memory in ieee802154_nl_fill_phy
Browse files Browse the repository at this point in the history
In net/ieee802154/nl-phy.c::ieee802154_nl_fill_phy() I see two small
issues.
1) If the allocation of 'buf' fails we may just as well return -EMSGSIZE
   directly rather than jumping to 'out:' and do a pointless kfree(0).
2) We do not free 'buf' unless we jump to one of the error labels and this
   leaks memory.
This patch should address both.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: David S. Miller <davem@conan.davemloft.net>
  • Loading branch information
Jesper Juhl authored and David S. Miller committed Jun 13, 2011
1 parent 84860c7 commit b9cabe5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/ieee802154/nl-phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid,
pr_debug("%s\n", __func__);

if (!buf)
goto out;
return -EMSGSIZE;

hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
IEEE802154_LIST_PHY);
Expand All @@ -65,6 +65,7 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid,
pages * sizeof(uint32_t), buf);

mutex_unlock(&phy->pib_lock);
kfree(buf);
return genlmsg_end(msg, hdr);

nla_put_failure:
Expand Down

0 comments on commit b9cabe5

Please sign in to comment.