Re: [PATCH] kernel/resource.c: fix memory leak

From: AmÃrico Wang
Date: Sat Jan 09 2010 - 11:56:05 EST


On Sat, Jan 09, 2010 at 05:46:35PM +0300, Alexander Beregalov wrote:
>Free res before exit.
>Found by cppcheck.
>
>Signed-off-by: Alexander Beregalov <a.beregalov@xxxxxxxxx>
>---
> kernel/resource.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
>diff --git a/kernel/resource.c b/kernel/resource.c
>index af96c1e..ae2e177 100644
>--- a/kernel/resource.c
>+++ b/kernel/resource.c
>@@ -545,11 +545,12 @@ static void __init __reserve_region_with_split(struct resource *root,
> res->flags = IORESOURCE_BUSY;
>
> conflict = __request_resource(parent, res);
>+ kfree(res);
>+
> if (!conflict)
> return;
>
> /* failed, split and try again */
>- kfree(res);
>
> /* conflict covered whole area */
> if (conflict->start <= start && conflict->end >= end)

NAK.

If I read it correctly, 'res' will be used if !conflict, we
should't kfree it.


--
Live like a child, think like the god.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/