lttng_list_sessions does not set the passed pointer to NULL on empty
return. This leads to a deallocation of an invalid pointer (segfault).
For returns of size 0, the value of the passed argument should be
considered "undefined".
Refactor error handling a bit by removing the "error" jump. Always
call free on the 'sessions' object.
Fixes #1205
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
int ret = CMD_SUCCESS;
int count, i;
unsigned int session_found = 0;
int ret = CMD_SUCCESS;
int count, i;
unsigned int session_found = 0;
- struct lttng_session *sessions;
+ struct lttng_session *sessions = NULL;
count = lttng_list_sessions(&sessions);
DBG("Session count %d", count);
count = lttng_list_sessions(&sessions);
DBG("Session count %d", count);
if (lttng_opt_mi) {
/* Mi */
if (session_name == NULL) {
if (lttng_opt_mi) {
/* Mi */
if (session_name == NULL) {
+ /* List all sessions */
ret = mi_list_sessions(sessions, count);
} else {
/* Note : this return an open session element */
ret = mi_list_sessions(sessions, count);
} else {
/* Note : this return an open session element */
}
if (ret) {
ret = CMD_ERROR;
}
if (ret) {
ret = CMD_ERROR;
}
} else {
/* Pretty print */
}
} else {
/* Pretty print */
if (!session_found && session_name != NULL) {
ERR("Session '%s' not found", session_name);
ret = CMD_ERROR;
if (!session_found && session_name != NULL) {
ERR("Session '%s' not found", session_name);
ret = CMD_ERROR;
}
if (session_name == NULL) {
}
if (session_name == NULL) {
-error:
- free(sessions);