Skip to contentSkip to conversation

drivers/char/pcmcia/ipwireless/hardware.c fix resource leak

PATCH In review Darren Jenkins\ 2 participants 2 messages Jul 6, 2008 – Jul 7, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/char/pcmcia/ipwireless/hardware.c fix resource leak

G'day people,

Coverity CID: 2172 RESOURCE_LEAK

When pool_allocate() tries to enlarge a packet, if it can not allocate enough memory, it returns NULL without first freeing the old packet.

This patch just frees the packet first.

Signed-off-by: Darren Jenkins <darrenrjenkins@gmailcom>

drivers/char/pcmcia/ipwireless/hardware.c +3 -1
index ba6340a..929101e 100644
@@ -590,8 +590,10 @@ static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
 		packet = kmalloc(sizeof(struct ipw_rx_packet) +
 				old_packet->length + minimum_free_space,
 				GFP_ATOMIC);
-		if (!packet)
+		if (!packet) {
+			kfree(old_packet);
 			return NULL;
+		}
 		memcpy(packet, old_packet,
 				sizeof(struct ipw_rx_packet)
 					+ old_packet->length);
#1 lore raw
Quoted 20 lines · Darren Jenkins\

G'day people,

Coverity CID: 2172 RESOURCE_LEAK

When pool_allocate() tries to enlarge a packet, if it can not allocate enough memory, it returns NULL without first freeing the old packet.

This patch just frees the packet first.

Signed-off-by: Darren Jenkins <darrenrjenkins@gmailcom>

drivers/char/pcmcia/ipwireless/hardware.c +0 -0
index ba6340a..929101e 100644
@@ -590,8 +590,10 @@ static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
 		packet = kmalloc(sizeof(struct ipw_rx_packet) +

drivers/char/pcmcia/ipwireless/hardware.c static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw, · line 599

Quoted 10 lines
drivers/char/pcmcia/ipwireless/hardware.c +3 -1
 				old_packet->length + minimum_free_space,
 				GFP_ATOMIC);
-		if (!packet)
+		if (!packet) {
+			kfree(old_packet);
 			return NULL;
+		}
 		memcpy(packet, old_packet,
 				sizeof(struct ipw_rx_packet)
 					+ old_packet->length);

Thanks a lot for reporting this, Darren.

Andrew, could you please push this through -mm? Thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs