[PATCH] infiniband-diags: preserve long_opts global for use in ibdiag_show_usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

	Calling ibdiag_show_usage after ibdiag_process_opts will result in
	using free'd memory.

Signed-off-by: Ira Weiny <weiny2@xxxxxxxx>
 src/ibdiag_common.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/ibdiag_common.c b/src/ibdiag_common.c
index 5752f95..d53398b 100644
--- a/src/ibdiag_common.c
+++ b/src/ibdiag_common.c
@@ -74,7 +74,7 @@ uint32_t ibd_ibnetdisc_flags = IBND_CONFIG_MLX_EPI;
 static const char *prog_name;
 static const char *prog_args;
 static const char **prog_examples;
-static struct option *long_opts;
+static struct option *long_opts = NULL;
 static const struct ibdiag_opt *opts_map[256];
 const static char *get_build_version(void)
@@ -357,6 +357,9 @@ int ibdiag_process_opts(int argc, char *const argv[], void *cxt,
 	prog_args = usage_args;
 	prog_examples = usage_examples;
+	if (long_opts)
+		free(long_opts);
 	long_opts = make_long_opts(exclude_common_str, custom_opts, opts_map);
 	if (!long_opts)
 		return -1;
@@ -380,8 +383,6 @@ int ibdiag_process_opts(int argc, char *const argv[], void *cxt,
-	free(long_opts);
 	return 0;

To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Home]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Free Online Dating]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Devices]

Add to Google Powered by Linux