lib/lru_cache: Fix error free handing in lc_create.
Subsystems (2)
PATCH 1/1 lib/lru_cache: Fix error free handing in lc_create.
When kmem_cache_alloc in function lc_create returns null, we will free the memory already allocated. The loop of kmem_cache_free is wrong, especially:
i = 0 ==> do wrong loop
i > 0 ==> do not free element[0]
Signed-off-by wuchi <[email protected]>
--- lib/lru_cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/lru_cache.c +2 -2
@@ -147,8 +147,8 @@ struct lru_cache *lc_create(const char *name, struct kmem_cache *cache,return lc;/* else: could not allocate all elements, give up */ -for (i--; i; i--) { -void *p = element[i]; +while (i) { +void *p = element[--i];kmem_cache_free (cache, p - e_off); }kfree (lc);
Signature · 1 line
2.20.1