X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fdestroy.cpp;fp=src%2Fbin%2Flttng%2Fcommands%2Fdestroy.cpp;h=9b5978bddc4962719260a6f5c44bb5bf7b07d2f8;hp=3ab9b224849180052f9755036abd279ab794fe6b;hb=5b915816f16e7cb3134dd7279abad79b31c2486c;hpb=3957512ed31ca945f8353d5812f317314c905640 diff --git a/src/bin/lttng/commands/destroy.cpp b/src/bin/lttng/commands/destroy.cpp index 3ab9b2248..9b5978bdd 100644 --- a/src/bin/lttng/commands/destroy.cpp +++ b/src/bin/lttng/commands/destroy.cpp @@ -22,7 +22,6 @@ #include #include -static char *opt_session_name; static int opt_destroy_all; static int opt_no_wait; @@ -270,6 +269,7 @@ int cmd_destroy(int argc, const char **argv) int ret = CMD_SUCCESS , i, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; + const char *arg_session_name = NULL; const char *leftover = NULL; struct lttng_session *sessions = NULL; @@ -342,18 +342,22 @@ int cmd_destroy(int argc, const char **argv) success = 0; } } else { - opt_session_name = (char *) poptGetArg(pc); + arg_session_name = poptGetArg(pc); - if (!opt_session_name) { + if (!arg_session_name) { /* No session name specified, lookup default */ session_name = get_session_name(); + } else { + session_name = strdup(arg_session_name); if (session_name == NULL) { - command_ret = CMD_ERROR; - success = 0; - goto mi_closing; + PERROR("Failed to copy session name"); } - } else { - session_name = opt_session_name; + } + + if (session_name == NULL) { + command_ret = CMD_ERROR; + success = 0; + goto mi_closing; } /* Find the corresponding lttng_session struct */ @@ -419,10 +423,7 @@ end: ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; } - if (opt_session_name == NULL) { - free(session_name); - } - + free(session_name); free(sessions); /* Overwrite ret if an error occurred during destroy_session/all */