Tests: fix: lttng-create: leaked command parameter
[lttng-tools.git] / src / bin / lttng / commands / create.c
index 438e88f4cadfeaa18e259d86047f40b9c88db2a8..705605c92826e3b214eaf2e05c47f449d418445b 100644 (file)
@@ -1,19 +1,9 @@
 /*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
- * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2011 EfficiOS Inc.
+ * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
@@ -41,6 +31,8 @@
 #include <common/utils.h>
 #include <lttng/snapshot.h>
 #include <lttng/session-descriptor.h>
+#include <common/path.h>
+#include <lttng/lttng.h>
 
 static char *opt_output_path;
 static char *opt_session_name;
@@ -511,7 +503,7 @@ error:
  *
  *  Spawn a session daemon by forking and execv.
  */
-static int spawn_sessiond(char *pathname)
+static int spawn_sessiond(const char *pathname)
 {
        int ret = 0;
        pid_t pid;
@@ -590,7 +582,7 @@ end:
 static int launch_sessiond(void)
 {
        int ret;
-       char *pathname = NULL;
+       const char *pathname = NULL;
 
        ret = lttng_session_daemon_alive();
        if (ret) {
@@ -637,6 +629,7 @@ end:
        return ret;
 }
 
+static
 int validate_url_option_combination(void)
 {
        int ret = 0;
@@ -681,6 +674,11 @@ int cmd_create(int argc, const char **argv)
                        uint64_t v;
 
                        errno = 0;
+                       if (opt_arg) {
+                               free(opt_arg);
+                               opt_arg = NULL;
+                       }
+
                        opt_arg = poptGetOptArg(pc);
                        if (!opt_arg) {
                                /* Set up default values. */
@@ -811,6 +809,7 @@ end:
        /* Overwrite ret if an error occurred in create_session() */
        ret = command_ret ? command_ret : ret;
 
+       free(opt_arg);
        poptFreeContext(pc);
        return ret;
 }
This page took 0.031932 seconds and 4 git commands to generate.