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

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