Skip to content

Commit

Permalink
fix for a memory leak in an error case introduced by fix for double free
Browse files Browse the repository at this point in the history
The fix NULLed a pointer without freeing it.

Signed-off-by: Oliver Neukum <oneukum@suse.de>
Reported-by: Juha Motorsportcom <juha_motorsportcom@luukku.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Oliver Neukum authored and Linus Torvalds committed Jul 27, 2008
1 parent 9ee08c2 commit 852fef6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/usb/serial/ipaq.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,17 @@ static int ipaq_open(struct tty_struct *tty,
*/

kfree(port->bulk_in_buffer);
kfree(port->bulk_out_buffer);
/* make sure the generic serial code knows */
port->bulk_out_buffer = NULL;

port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
if (port->bulk_in_buffer == NULL) {
port->bulk_out_buffer = NULL; /* prevent double free */
if (port->bulk_in_buffer == NULL)
goto enomem;
}

kfree(port->bulk_out_buffer);
port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
if (port->bulk_out_buffer == NULL) {
/* the buffer is useless, free it */
kfree(port->bulk_in_buffer);
port->bulk_in_buffer = NULL;
goto enomem;
Expand Down

0 comments on commit 852fef6

Please sign in to comment.