diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2014-10-01 04:30:57 -0400 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2014-10-02 06:41:32 -0400 |
commit | a7807d73a0fa9b33dbdfd5f1cb97970ccc91d77e (patch) | |
tree | b1b369c0f169d5c16d21f3cbe2bf998649dd4796 | |
parent | fc12518a4bcbd4214652291df76f692343bca3d5 (diff) |
Bluetooth: 6lowpan: Avoid memory leak if memory allocation fails
If skb_unshare() returns NULL, then we leak the original skb.
Solution is to use temp variable to hold the new skb.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
-rw-r--r-- | net/bluetooth/6lowpan.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index add2b58312d7..44eaad77e70c 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c | |||
@@ -589,13 +589,17 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
589 | int err = 0; | 589 | int err = 0; |
590 | bdaddr_t addr; | 590 | bdaddr_t addr; |
591 | u8 addr_type; | 591 | u8 addr_type; |
592 | struct sk_buff *tmpskb; | ||
592 | 593 | ||
593 | /* We must take a copy of the skb before we modify/replace the ipv6 | 594 | /* We must take a copy of the skb before we modify/replace the ipv6 |
594 | * header as the header could be used elsewhere | 595 | * header as the header could be used elsewhere |
595 | */ | 596 | */ |
596 | skb = skb_unshare(skb, GFP_ATOMIC); | 597 | tmpskb = skb_unshare(skb, GFP_ATOMIC); |
597 | if (!skb) | 598 | if (!tmpskb) { |
599 | kfree_skb(skb); | ||
598 | return NET_XMIT_DROP; | 600 | return NET_XMIT_DROP; |
601 | } | ||
602 | skb = tmpskb; | ||
599 | 603 | ||
600 | /* Return values from setup_header() | 604 | /* Return values from setup_header() |
601 | * <0 - error, packet is dropped | 605 | * <0 - error, packet is dropped |