From 68cb9a0e6c7991280154387527cd919e92d05c20 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 22 Apr 2021 15:05:07 +0200 Subject: [PATCH] lib:replace: Fix a memleak in test_strndup() Found by covscan Signed-off-by: Andreas Schneider Reviewed-by: Jeremy Allison --- lib/replace/tests/testsuite.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/replace/tests/testsuite.c b/lib/replace/tests/testsuite.c index 6d87b8ed611..670ff85029d 100644 --- a/lib/replace/tests/testsuite.c +++ b/lib/replace/tests/testsuite.c @@ -264,26 +264,34 @@ static int test_setenv(void) static int test_strndup(void) { char *x; + int cmp; + printf("test: strndup\n"); x = strndup("bla", 0); - if (strcmp(x, "") != 0) { + cmp = strcmp(x, ""); + free(x); + if (cmp != 0) { printf("failure: strndup [\ninvalid\n]\n"); return false; } - free(x); + x = strndup("bla", 2); - if (strcmp(x, "bl") != 0) { + cmp = strcmp(x, "bl"); + free(x); + if (cmp != 0) { printf("failure: strndup [\ninvalid\n]\n"); return false; } - free(x); + x = strndup("bla", 10); - if (strcmp(x, "bla") != 0) { + cmp = strcmp(x, "bla"); + free(x); + if (cmp != 0) { printf("failure: strndup [\ninvalid\n]\n"); free(x); return false; } - free(x); + printf("success: strndup\n"); return true; } -- 2.47.3