From: Dave Jones Date: Sun, 28 Jan 2007 22:39:19 +0000 (-0500) Subject: [AGPGART] Prevent (unlikely) memory leak in amd_create_gatt_pages() X-Git-Tag: v2.6.20-rc7~16^2~3 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c30efbaeaa9297fb1a35ef952350e0c2bb7a3d47;p=linux-2.6 [AGPGART] Prevent (unlikely) memory leak in amd_create_gatt_pages() If we fail an alloc, unwind the previous allocs that succeeded. Spotted-by: Alan Grimes Signed-off-by: Dave Jones --- diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c index 51d0d562d0..c85c8cadb6 100644 --- a/drivers/char/agp/amd-k7-agp.c +++ b/drivers/char/agp/amd-k7-agp.c @@ -101,6 +101,11 @@ static int amd_create_gatt_pages(int nr_tables) for (i = 0; i < nr_tables; i++) { entry = kzalloc(sizeof(struct amd_page_map), GFP_KERNEL); if (entry == NULL) { + while (i > 0) { + kfree(tables[i-1]); + i--; + } + kfree(tables); retval = -ENOMEM; break; }