app: don't leak memory after failed arg parsing
This is in response to a scan-build error introduced with clang 6.0 Change-Id: Iee5a2538ec9a6575e5b3087bf43b8ded5d099fe7 Signed-off-by: Seth Howell <seth.howell@intel.com> Reviewed-on: https://review.gerrithub.io/424576 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
51ce4dd231
commit
d70941c3d5
@ -862,6 +862,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
|
||||
case PCI_BLACKLIST_OPT_IDX:
|
||||
if (opts->pci_whitelist) {
|
||||
free(opts->pci_whitelist);
|
||||
opts->pci_whitelist = NULL;
|
||||
fprintf(stderr, "-B and -W cannot be used at the same time\n");
|
||||
usage(app_usage);
|
||||
goto out;
|
||||
@ -870,6 +871,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
|
||||
rc = spdk_app_opts_add_pci_addr(opts, &opts->pci_blacklist, optarg);
|
||||
if (rc != 0) {
|
||||
free(opts->pci_blacklist);
|
||||
opts->pci_blacklist = NULL;
|
||||
goto out;
|
||||
}
|
||||
break;
|
||||
@ -895,6 +897,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
|
||||
case PCI_WHITELIST_OPT_IDX:
|
||||
if (opts->pci_blacklist) {
|
||||
free(opts->pci_blacklist);
|
||||
opts->pci_blacklist = NULL;
|
||||
fprintf(stderr, "-B and -W cannot be used at the same time\n");
|
||||
usage(app_usage);
|
||||
goto out;
|
||||
@ -903,6 +906,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
|
||||
rc = spdk_app_opts_add_pci_addr(opts, &opts->pci_whitelist, optarg);
|
||||
if (rc != 0) {
|
||||
free(opts->pci_whitelist);
|
||||
opts->pci_whitelist = NULL;
|
||||
goto out;
|
||||
}
|
||||
break;
|
||||
@ -928,6 +932,12 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
|
||||
|
||||
retval = SPDK_APP_PARSE_ARGS_SUCCESS;
|
||||
out:
|
||||
if (retval != SPDK_APP_PARSE_ARGS_SUCCESS) {
|
||||
free(opts->pci_blacklist);
|
||||
opts->pci_blacklist = NULL;
|
||||
free(opts->pci_whitelist);
|
||||
opts->pci_whitelist = NULL;
|
||||
}
|
||||
free(cmdline_short_opts);
|
||||
free(cmdline_options);
|
||||
return retval;
|
||||
|
@ -152,7 +152,7 @@ test_spdk_app_parse_args(void)
|
||||
|
||||
/* Specify -B and -W options at the same time. Expected result: FAIL */
|
||||
rc = spdk_app_parse_args(test_argc, invalid_argv_BW, &opts, "", NULL, unittest_parse_args, NULL);
|
||||
CU_ASSERT_EQUAL(rc, SPDK_APP_PARSE_ARGS_FAIL);
|
||||
SPDK_CU_ASSERT_FATAL(rc == SPDK_APP_PARSE_ARGS_FAIL);
|
||||
optind = 1;
|
||||
|
||||
/* Omit necessary argument to option */
|
||||
|
Loading…
Reference in New Issue
Block a user