Blame SOURCES/0006-ndptool-fix-potential-memory-leak-caused-by-strdup.patch

f9401c
From 27403f898372e99b0ad916bebe2bc29e95bee1f0 Mon Sep 17 00:00:00 2001
f9401c
From: Hangbin Liu <haliu@redhat.com>
f9401c
Date: Tue, 24 Sep 2019 14:17:56 +0800
f9401c
Subject: [PATCH 06/06] ndptool: fix potential memory leak caused by strdup
f9401c
f9401c
We use strdup to copy the parameters. As strdup will call malloc when
f9401c
obtain the memory, we need to free them before exit, or there will be
f9401c
memory leak. This is found by covscan.
f9401c
f9401c
Signed-off-by: Hangbin Liu <haliu@redhat.com>
f9401c
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
f9401c
---
f9401c
 utils/ndptool.c | 11 ++++++++---
f9401c
 1 file changed, 8 insertions(+), 3 deletions(-)
f9401c
f9401c
diff --git a/utils/ndptool.c b/utils/ndptool.c
f9401c
index 1131462..4eca83d 100644
f9401c
--- a/utils/ndptool.c
f9401c
+++ b/utils/ndptool.c
f9401c
@@ -416,7 +416,8 @@ int main(int argc, char **argv)
f9401c
 		switch(opt) {
f9401c
 		case 'h':
f9401c
 			print_help(argv0);
f9401c
-			return EXIT_SUCCESS;
f9401c
+			res = EXIT_SUCCESS;
f9401c
+			goto errout;
f9401c
 		case 'v':
f9401c
 			g_verbosity++;
f9401c
 			break;
f9401c
@@ -442,11 +443,11 @@ int main(int argc, char **argv)
f9401c
 		case '?':
f9401c
 			pr_err("unknown option.\n");
f9401c
 			print_help(argv0);
f9401c
-			return EXIT_FAILURE;
f9401c
+			goto errout;
f9401c
 		default:
f9401c
 			pr_err("unknown option \"%c\".\n", opt);
f9401c
 			print_help(argv0);
f9401c
-			return EXIT_FAILURE;
f9401c
+			goto errout;
f9401c
 		}
f9401c
 	}
f9401c
 
f9401c
@@ -530,5 +531,9 @@ int main(int argc, char **argv)
f9401c
 ndp_close:
f9401c
 	ndp_close(ndp);
f9401c
 errout:
f9401c
+	free(msgtypestr);
f9401c
+	free(ifname);
f9401c
+	free(daddr);
f9401c
+	free(taddr);
f9401c
 	return res;
f9401c
 }
f9401c
-- 
f9401c
2.19.2
f9401c