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;
}
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();
success = 0;
goto mi_closing;
}
+ free_session_name = true;
}
} else {
session_name = NULL;
}
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;