2011-02-10 18:00:47

by Vasily Kulikov

[permalink] [raw]
Subject: [PATCH] staging: zcache: fix memory leak

obj is not freed if __get_free_page() failed.

Signed-off-by: Vasiliy Kulikov <[email protected]>
---
Compile tested only.

drivers/staging/zcache/zcache.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/zcache/zcache.c b/drivers/staging/zcache/zcache.c
index 61be849..b8a2b30 100644
--- a/drivers/staging/zcache/zcache.c
+++ b/drivers/staging/zcache/zcache.c
@@ -790,6 +790,7 @@ static int zcache_do_preload(struct tmem_pool *pool)
page = (void *)__get_free_page(ZCACHE_GFP_MASK);
if (unlikely(page == NULL)) {
zcache_failed_get_free_pages++;
+ kmem_cache_free(zcache_obj_cache, obj);
goto unlock_out;
}
preempt_disable();
--
1.7.0.4


2011-02-10 18:33:16

by Dan Magenheimer

[permalink] [raw]
Subject: RE: [PATCH] staging: zcache: fix memory leak

> From: Vasiliy Kulikov [mailto:[email protected]]
> Sent: Thursday, February 10, 2011 11:01 AM
>
> obj is not freed if __get_free_page() failed.
>
> Signed-off-by: Vasiliy Kulikov <[email protected]>

Thanks Vasiliy! Good catch!

> drivers/staging/zcache/zcache.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/staging/zcache/zcache.c
> b/drivers/staging/zcache/zcache.c
> index 61be849..b8a2b30 100644
> --- a/drivers/staging/zcache/zcache.c
> +++ b/drivers/staging/zcache/zcache.c
> @@ -790,6 +790,7 @@ static int zcache_do_preload(struct tmem_pool
> *pool)
> page = (void *)__get_free_page(ZCACHE_GFP_MASK);
> if (unlikely(page == NULL)) {
> zcache_failed_get_free_pages++;
> + kmem_cache_free(zcache_obj_cache, obj);
> goto unlock_out;
> }
> preempt_disable();

Acked-by: Dan Magenheimer <[email protected]>