X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fclear.c;h=61879d61d1d9fd06751c736f5fd813be57bf94f2;hb=81663f073dbfb4b61c06a0ceb8ca33c4fc41b1c5;hp=353c855c6f11aed6036f6a8f855035d31d7f8b54;hpb=511ed4e25eeb6821dc4f4b6c573fbbdc07c17053;p=lttng-tools.git diff --git a/src/bin/lttng/commands/clear.c b/src/bin/lttng/commands/clear.c index 353c855c6..61879d61d 100644 --- a/src/bin/lttng/commands/clear.c +++ b/src/bin/lttng/commands/clear.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2019 - Jonathan Rajotte-Julien + * Copyright (C) 2019 Jonathan Rajotte * - * 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 @@ -24,8 +14,7 @@ #include #include #include -#include -#include +#include #include "../command.h" @@ -168,7 +157,7 @@ int cmd_clear(int argc, const char **argv) static poptContext pc; char *session_name = NULL; const char *leftover = NULL; - + bool free_session_name = false; struct lttng_session *sessions = NULL; int count; int found; @@ -224,13 +213,7 @@ int cmd_clear(int argc, const char **argv) } if (!opt_clear_all) { - /* - * popt expects us to free this even if it returns a const char *. - * See https://www.mail-archive.com/popt-devel@rpm5.org/msg00193.html - * Force cast to char * allowing later freeing if necessary. - */ session_name = (char *) poptGetArg(pc); - if (!session_name) { /* No session name specified, lookup default */ session_name = get_session_name(); @@ -239,6 +222,7 @@ int cmd_clear(int argc, const char **argv) success = 0; goto mi_closing; } + free_session_name = true; } } else { session_name = NULL; @@ -323,7 +307,9 @@ end: } free(sessions); - free(session_name); + if (free_session_name) { + free(session_name); + } /* Overwrite ret if an error occurred during clear_session/all */ ret = command_ret ? command_ret : ret;