Fix: leaking memory from strdup in lttng-crash
[lttng-tools.git] / src / bin / lttng-crash / lttng-crash.c
index 94943fbb9a857f5e972f5bb0e632f03032651ade..043acafaec7d50ed5aef39249b661dadeedd0e3c 100644 (file)
@@ -183,8 +183,8 @@ struct lttng_crash_layout {
 
 /* Variables */
 static char *progname,
-       *opt_viewer_path = DEFAULT_VIEWER,
-       *opt_output_path;
+       *opt_viewer_path = NULL,
+       *opt_output_path = NULL;
 
 static char *input_path;
 
@@ -291,9 +291,11 @@ static int parse_args(int argc, char **argv)
                        }
                        break;
                case 'e':
+                       free(opt_viewer_path);
                        opt_viewer_path = strdup(optarg);
                        break;
                case 'x':
+                       free(opt_output_path);
                        opt_output_path = strdup(optarg);
                        break;
                case OPT_DUMP_OPTIONS:
@@ -306,6 +308,10 @@ static int parse_args(int argc, char **argv)
                }
        }
 
+       if (!opt_viewer_path) {
+               opt_viewer_path = DEFAULT_VIEWER;
+       }
+
        /* No leftovers, or more than one input path, print usage and quit */
        if ((argc - optind) == 0 || (argc - optind) > 1) {
                usage(stderr);
This page took 0.02674 seconds and 4 git commands to generate.