Freeing non-dynamically allocated memory is never a good idea.
Also fixing 2 memory leaks.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ret = CMD_SUCCESS;
free_name:
- free(session_name);
+ if (opt_session_name == NULL) {
+ free(session_name);
+ }
error:
return ret;
}
static int disable_events(void)
{
int err, ret = CMD_SUCCESS;
- char *event_name, *channel_name;
+ char *event_name, *channel_name = NULL;
struct lttng_event ev;
if (set_session_name(opt_session_name) < 0) {
}
error:
+ if (opt_channel_name == NULL) {
+ free(channel_name);
+ }
return ret;
}
static int enable_events(void)
{
int err, ret = CMD_SUCCESS;
- char *event_name, *channel_name;
+ char *event_name, *channel_name = NULL;
struct lttng_event ev;
if (set_session_name(opt_session_name) < 0) {
}
error:
+ if (opt_channel_name == NULL) {
+ free(channel_name);
+ }
return ret;
}
MSG("Tracing started for session %s", session_name);
free_name:
- free(session_name);
+ if (opt_session_name == NULL) {
+ free(session_name);
+ }
error:
return ret;
}
MSG("Tracing stopped for session %s", session_name);
free_name:
- free(session_name);
+ if (opt_session_name == NULL) {
+ free(session_name);
+ }
error:
return ret;
}
int ret;
char *session_name;
- if (name != NULL) {
- session_name = name;
- } else {
+ if (!name) {
session_name = get_session_name();
if (session_name == NULL) {
ret = -1;
goto error;
}
+ } else {
+ session_name = name;
}
lttng_set_session_name(session_name);
- free(session_name);
+ if (!name)
+ free(session_name);
ret = 0;