From 550004b427608c43666ed59b552c37ea900ad6f8 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 29 Jul 2019 10:06:58 -0400 Subject: [PATCH] Fix: live_viewer_connection_create(): `lttng_live_msg_iter` can be `NULL` Because `lttng_live_msg_iter` can be `NULL` in live_viewer_connection_create() when it's used from a query operation, pass the log level to use directly and only read `self_comp` if `lttng_live_msg_iter` exists. Signed-off-by: Philippe Proulx Change-Id: Ied5ec621bcd066df0bb312a6f81899616f9d1a9f Reviewed-on: https://review.lttng.org/c/babeltrace/+/1797 --- src/plugins/ctf/lttng-live/lttng-live.c | 5 +++-- src/plugins/ctf/lttng-live/viewer-connection.c | 13 +++++++++---- src/plugins/ctf/lttng-live/viewer-connection.h | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index 5946f064..f13a5eab 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -1337,7 +1337,7 @@ bt_component_class_message_iterator_init_method_status lttng_live_msg_iter_init( lttng_live_msg_iter->viewer_connection = live_viewer_connection_create(lttng_live->params.url->str, false, - lttng_live_msg_iter); + lttng_live_msg_iter, log_level); if (!lttng_live_msg_iter->viewer_connection) { goto error; } @@ -1424,7 +1424,8 @@ bt_component_class_query_method_status lttng_live_query_list_sessions( url = bt_value_string_get(url_value); - viewer_connection = live_viewer_connection_create(url, true, NULL); + viewer_connection = live_viewer_connection_create(url, true, NULL, + log_level); if (!viewer_connection) { goto error; } diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index 8c02be02..c7347020 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -1466,18 +1466,23 @@ error: BT_HIDDEN struct live_viewer_connection *live_viewer_connection_create( const char *url, bool in_query, - struct lttng_live_msg_iter *lttng_live_msg_iter) + struct lttng_live_msg_iter *lttng_live_msg_iter, + bt_logging_level log_level) { struct live_viewer_connection *viewer_connection; viewer_connection = g_new0(struct live_viewer_connection, 1); - if (bt_socket_init(lttng_live_msg_iter->log_level) != 0) { + if (bt_socket_init(log_level) != 0) { goto error; } - viewer_connection->log_level = lttng_live_msg_iter->log_level; - viewer_connection->self_comp = lttng_live_msg_iter->self_comp; + viewer_connection->log_level = log_level; + + if (lttng_live_msg_iter) { + viewer_connection->self_comp = lttng_live_msg_iter->self_comp; + } + bt_object_init_shared(&viewer_connection->obj, connection_release); viewer_connection->control_sock = BT_INVALID_SOCKET; viewer_connection->port = -1; diff --git a/src/plugins/ctf/lttng-live/viewer-connection.h b/src/plugins/ctf/lttng-live/viewer-connection.h index 549a9003..94073426 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.h +++ b/src/plugins/ctf/lttng-live/viewer-connection.h @@ -86,7 +86,8 @@ struct packet_index { struct live_viewer_connection * live_viewer_connection_create( const char *url, bool in_query, - struct lttng_live_msg_iter *lttng_live_msg_iter); + struct lttng_live_msg_iter *lttng_live_msg_iter, + bt_logging_level log_level); void live_viewer_connection_destroy( struct live_viewer_connection *conn); -- 2.34.1