The session_name should not be free(3) if the user has specified a
session name on the command line. Also, the caller is responsible to
free the allocated string when calling get_session_name(). Handle both
cases gracefully.
Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
#include <common/sessiond-comm/sessiond-comm.h>
#include <common/sessiond-comm/sessiond-comm.h>
+static char *opt_session_name;
static int opt_destroy_all;
enum {
static int opt_destroy_all;
enum {
- session_name = (char *) poptGetArg(pc);
-
- /*
- * ignore session name in case all
- * sessions are to be destroyed
- */
+ /* Ignore session name in case all sessions are to be destroyed */
if (opt_destroy_all) {
ret = destroy_all_sessions();
goto end;
}
if (opt_destroy_all) {
ret = destroy_all_sessions();
goto end;
}
- if (session_name == NULL) {
- ret = get_default_session_name(&session_name);
- if (ret < 0 || session_name == NULL) {
+
+ opt_session_name = (char *) poptGetArg(pc);
+
+ if (opt_session_name == NULL) {
+ /* No session name specified, lookup default */
+ session_name = get_session_name();
+ if (session_name == NULL) {
+ ret = CMD_ERROR;
+ } else {
+ session_name = opt_session_name;
ret = destroy_session(session_name);
end:
ret = destroy_session(session_name);
end:
- poptFreeContext(pc);
- if (session_name != NULL) {
+ if (opt_session_name == NULL) {