[PATCH] lib/test_kasan.c: Fix memory leak in kmalloc_oob_krealloc_more()

From: Gustavo A. R. Silva
Date: Thu Jan 23 2020 - 11:24:05 EST


In case memory resources for _ptr2_ were allocated, release them
before return.

Notice that in case _ptr1_ happens to be NULL, krealloc() behaves
exactly like kmalloc().

Addresses-Coverity-ID: 1490594 ("Resource leak")
Fixes: 3f15801cdc23 ("lib: add kasan test module")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Gustavo A. R. Silva <gustavo@xxxxxxxxxxxxxx>
---
lib/test_kasan.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 328d33beae36..3872d250ed2c 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -158,6 +158,7 @@ static noinline void __init kmalloc_oob_krealloc_more(void)
if (!ptr1 || !ptr2) {
pr_err("Allocation failed\n");
kfree(ptr1);
+ kfree(ptr2);
return;
}

--
2.25.0