* [PATCH] lib/lru_cache: Fix error free handing in lc_create.
@ 2022-06-18 8:25 wuchi
0 siblings, 0 replies; only message in thread
From: wuchi @ 2022-06-18 8:25 UTC (permalink / raw)
To: philipp.reisner, lars.ellenberg, christoph.boehmwalder; +Cc: akpm, linux-kernel
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 <wuchi.zero@gmail.com>
---
lib/lru_cache.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/lru_cache.c b/lib/lru_cache.c
index 52313acbfa62..dc35464216d3 100644
--- a/lib/lru_cache.c
+++ b/lib/lru_cache.c
@@ -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);
--
2.20.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-18 8:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-18 8:25 [PATCH] lib/lru_cache: Fix error free handing in lc_create wuchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox