Commit d70941c3 authored by Seth Howell's avatar Seth Howell Committed by Jim Harris
Browse files

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: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/424576


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
parent 51ce4dd2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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 */