Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/char/agp/parisc-agp.c: eliminate memory leak

alloc_pci_dev allocates some memory, so that memory should be freed before
leaving the function in an error case.

A simplified version of the semantic match that finds this problem is:
(http://coccinelle.lip6.fr/)

// <smpl>
@r exists@
local idexpression x;
expression E;
identifier f1;
iterator I;
@@

x = alloc_pci_dev(...);
<... when != x
when != true (x == NULL || ...)
when != if (...) { <+...x...+> }
when != I (...) { <+...x...+> }
(
x == NULL
|
x == E
|
x->f1
)
...>
* return ...;
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Dan Carpenter <error27@gmail.com>
Dave Airlie <airlied@linux.ie>
Cc: Helge Deller <deller@gmx.de>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Kyle McMartin <kyle@redhat.com>

authored by

Julia Lawall and committed by
Kyle McMartin
338e4fab 7da12725

+4
+4
drivers/char/agp/parisc-agp.c
··· 358 358 bridge->dev = fake_bridge_dev; 359 359 360 360 error = agp_add_bridge(bridge); 361 + if (error) 362 + goto fail; 363 + return 0; 361 364 362 365 fail: 366 + kfree(fake_bridge_dev); 363 367 return error; 364 368 } 365 369