summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHangbin Liu <haliu@redhat.com>2019-09-24 14:17:56 +0800
committerJiri Pirko <jiri@mellanox.com>2019-09-24 08:42:49 +0200
commit27403f898372e99b0ad916bebe2bc29e95bee1f0 (patch)
treeb2d2825c44550b1ac4c28d5060430801c7398642
parente9a35fba03ec3670586fba7debd2e0cb3cd4341e (diff)
downloadlibndp-27403f898372e99b0ad916bebe2bc29e95bee1f0.tar.gz
ndptool: fix potential memory leak caused by strdup
We use strdup to copy the parameters. As strdup will call malloc when obtain the memory, we need to free them before exit, or there will be memory leak. This is found by covscan. Signed-off-by: Hangbin Liu <haliu@redhat.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
-rw-r--r--utils/ndptool.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/utils/ndptool.c b/utils/ndptool.c
index 1131462..4eca83d 100644
--- a/utils/ndptool.c
+++ b/utils/ndptool.c
@@ -416,7 +416,8 @@ int main(int argc, char **argv)
switch(opt) {
case 'h':
print_help(argv0);
- return EXIT_SUCCESS;
+ res = EXIT_SUCCESS;
+ goto errout;
case 'v':
g_verbosity++;
break;
@@ -442,11 +443,11 @@ int main(int argc, char **argv)
case '?':
pr_err("unknown option.\n");
print_help(argv0);
- return EXIT_FAILURE;
+ goto errout;
default:
pr_err("unknown option \"%c\".\n", opt);
print_help(argv0);
- return EXIT_FAILURE;
+ goto errout;
}
}
@@ -530,5 +531,9 @@ int main(int argc, char **argv)
ndp_close:
ndp_close(ndp);
errout:
+ free(msgtypestr);
+ free(ifname);
+ free(daddr);
+ free(taddr);
return res;
}