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>
This commit is contained in:
		
					parent
					
						
							
								fc12518a4b
							
						
					
				
			
			
				commit
				
					
						a7807d73a0
					
				
			
		
					 1 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -589,13 +589,17 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
 | 
				
			||||||
	int err = 0;
 | 
						int err = 0;
 | 
				
			||||||
	bdaddr_t addr;
 | 
						bdaddr_t addr;
 | 
				
			||||||
	u8 addr_type;
 | 
						u8 addr_type;
 | 
				
			||||||
 | 
						struct sk_buff *tmpskb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* We must take a copy of the skb before we modify/replace the ipv6
 | 
						/* We must take a copy of the skb before we modify/replace the ipv6
 | 
				
			||||||
	 * header as the header could be used elsewhere
 | 
						 * header as the header could be used elsewhere
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	skb = skb_unshare(skb, GFP_ATOMIC);
 | 
						tmpskb = skb_unshare(skb, GFP_ATOMIC);
 | 
				
			||||||
	if (!skb)
 | 
						if (!tmpskb) {
 | 
				
			||||||
 | 
							kfree_skb(skb);
 | 
				
			||||||
		return NET_XMIT_DROP;
 | 
							return NET_XMIT_DROP;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						skb = tmpskb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Return values from setup_header()
 | 
						/* Return values from setup_header()
 | 
				
			||||||
	 *  <0 - error, packet is dropped
 | 
						 *  <0 - error, packet is dropped
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue