src.ctf.lttng-live: use GCharUP in lttng_live_component_create
[babeltrace.git] / src / plugins / ctf / lttng-live / lttng-live.cpp
index 7d687b3ebf1574b30d696c492f163b89d27e2170..d3f2c22d1e6f368707f41d64f03453e0bb9eb2cf 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "common/assert.h"
 #include "cpp-common/bt2c/fmt.hpp"
+#include "cpp-common/bt2c/glib-up.hpp"
 #include "cpp-common/vendor/fmt/format.h"
 
 #include "plugins/common/muxing/muxing.h"
@@ -1713,7 +1714,7 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
         }
 
         viewer_status = live_viewer_connection_create(
-            lttng_live->params.url->str, false, lttng_live_msg_iter, lttng_live_msg_iter->logger,
+            lttng_live->params.url.c_str(), false, lttng_live_msg_iter, lttng_live_msg_iter->logger,
             &lttng_live_msg_iter->viewer_connection);
         if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
             if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
@@ -1758,7 +1759,7 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
                     "Unable to connect to the requested live viewer session. "
                     "Keep trying to connect because of {}=\"{}\" component parameter: url=\"{}\"",
                     SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_CONTINUE_STR,
-                    lttng_live->params.url->str);
+                    lttng_live->params.url);
                 break;
             case SESSION_NOT_FOUND_ACTION_FAIL:
                 BT_CPPLOGE_APPEND_CAUSE_SPEC(
@@ -1767,7 +1768,7 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
                     "Fail the message iterator initialization because of {}=\"{}\" "
                     "component parameter: url =\"{}\"",
                     SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_FAIL_STR,
-                    lttng_live->params.url->str);
+                    lttng_live->params.url);
                 status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
                 goto error;
             case SESSION_NOT_FOUND_ACTION_END:
@@ -1776,7 +1777,7 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
                                 "End gracefully at the first _next() call because of {}=\"{}\""
                                 " component parameter: url=\"{}\"",
                                 SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_END_STR,
-                                lttng_live->params.url->str);
+                                lttng_live->params.url);
                 break;
             default:
                 bt_common_abort();
@@ -1968,28 +1969,12 @@ end:
     }
 }
 
-static void lttng_live_component_destroy_data(struct lttng_live_component *lttng_live)
-{
-    if (!lttng_live) {
-        return;
-    }
-
-    if (lttng_live->params.url) {
-        g_string_free(lttng_live->params.url, TRUE);
-    }
-
-    delete lttng_live;
-}
-
 void lttng_live_component_finalize(bt_self_component_source *component)
 {
     lttng_live_component *data = (lttng_live_component *) bt_self_component_get_data(
         bt_self_component_source_as_self_component(component));
 
-    if (!data) {
-        return;
-    }
-    lttng_live_component_destroy_data(data);
+    delete data;
 }
 
 static enum session_not_found_action
@@ -2034,7 +2019,6 @@ lttng_live_component_create(const bt_value *params, bt_self_component_source *se
     const bt_value *inputs_value;
     const bt_value *url_value;
     const bt_value *value;
-    const char *url;
     enum bt_param_validation_status validation_status;
     gchar *validation_error = NULL;
     bt_component_class_initialize_method_status status;
@@ -2045,6 +2029,7 @@ lttng_live_component_create(const bt_value *params, bt_self_component_source *se
         status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
         goto error;
     } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) {
+        bt2c::GCharUP errorFreer {validation_error};
         BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "{}", validation_error);
         status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
         goto error;
@@ -2057,13 +2042,7 @@ lttng_live_component_create(const bt_value *params, bt_self_component_source *se
 
     inputs_value = bt_value_map_borrow_entry_value_const(params, INPUTS_PARAM);
     url_value = bt_value_array_borrow_element_by_index_const(inputs_value, 0);
-    url = bt_value_string_get(url_value);
-
-    lttng_live->params.url = g_string_new(url);
-    if (!lttng_live->params.url) {
-        status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
-        goto error;
-    }
+    lttng_live->params.url = bt_value_string_get(url_value);
 
     value = bt_value_map_borrow_entry_value_const(params, SESS_NOT_FOUND_ACTION_PARAM);
     if (value) {
@@ -2079,11 +2058,9 @@ lttng_live_component_create(const bt_value *params, bt_self_component_source *se
     goto end;
 
 error:
-    lttng_live_component_destroy_data(lttng_live);
+    delete lttng_live;
     lttng_live = NULL;
 end:
-    g_free(validation_error);
-
     *component = lttng_live;
     return status;
 }
@@ -2114,7 +2091,7 @@ lttng_live_component_init(bt_self_component_source *self_comp_src,
         goto end;
 
 error:
-        lttng_live_component_destroy_data(lttng_live);
+        delete lttng_live;
         lttng_live = NULL;
 end:
         return ret;
This page took 0.025072 seconds and 4 git commands to generate.