summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavo@embeddedor.com>2020-01-30 22:13:51 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-02-14 16:29:55 -0500
commit09937b5744ef814a9153bd3d8de54b188a699775 (patch)
tree0b852ed6f2805d26aa5beb4f5c64e033a31a8445
parent4daec55c62aee308bf265a557369d7fcdad60b77 (diff)
downloadlinux-stable-09937b5744ef814a9153bd3d8de54b188a699775.tar.gz
linux-stable-09937b5744ef814a9153bd3d8de54b188a699775.tar.bz2
linux-stable-09937b5744ef814a9153bd3d8de54b188a699775.zip
lib/test_kasan.c: fix memory leak in kmalloc_oob_krealloc_more()
commit 3e21d9a501bf99aee2e5835d7f34d8c823f115b5 upstream. 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") Link: http://lkml.kernel.org/r/20200123160115.GA4202@embeddedor Fixes: 3f15801cdc23 ("lib: add kasan test module") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--lib/test_kasan.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index c32f3b0048dc..275ff0b5162e 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -93,6 +93,7 @@ static noinline void __init kmalloc_oob_krealloc_more(void)
if (!ptr1 || !ptr2) {
pr_err("Allocation failed\n");
kfree(ptr1);
+ kfree(ptr2);
return;
}