src.ctf.lttng-live: add bt_common_lttng_live_url_parts_deleter
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 2 Nov 2023 18:57:32 +0000 (18:57 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
bt_common_lttng_live_url_parts can't be made a C++ object that
automatically manages its memory yet, since it's used in
babeltrace2-cfg-cli-args.c (C code).  Add an RAII type in lttng-live to
automatically call bt_common_destroy_lttng_live_url_parts in two places.

Change-Id: I233a5ba5a2829f4577c4ebbcc1ab0e630d039174
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8475
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12390
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/lttng-live/lttng-live.cpp
src/plugins/ctf/lttng-live/lttng-live.hpp
src/plugins/ctf/lttng-live/viewer-connection.cpp

index 1b5c90ee0252e87cea509b97c404050bc7b2a6ae..26beceda15fb5595eae19734112caeca21ccec81 100644 (file)
@@ -1751,6 +1751,7 @@ lttng_live_query_support_info(const bt_value *params, const bt_value **result,
     const bt_value *input_value;
     double weight = 0;
     struct bt_common_lttng_live_url_parts parts = {};
+    bt_common_lttng_live_url_parts_deleter partsDeleter {parts};
 
     /* Used by the logging macros */
     __attribute__((unused)) bt_self_component *self_comp = NULL;
@@ -1809,7 +1810,6 @@ error:
     BT_ASSERT(!*result);
 
 end:
-    bt_common_destroy_lttng_live_url_parts(&parts);
     return status;
 }
 
index cbdf27d80d05a7016a4c0db7804a53b317ec2f6c..9dbc432abf3f527abc3ef64017b474aab2ddbc3d 100644 (file)
 #include "../common/src/msg-iter/msg-iter.hpp"
 #include "viewer-connection.hpp"
 
+/*
+ * bt_common_lttng_live_url_parts is defined in common code, and is also used
+ * by C code, so it can't be C++-ified yet.  Use this separate deleter object
+ * in the mean time.
+ */
+struct bt_common_lttng_live_url_parts_deleter
+{
+    explicit bt_common_lttng_live_url_parts_deleter(bt_common_lttng_live_url_parts& obj) noexcept :
+        _mObj {&obj}
+    {
+    }
+
+    bt_common_lttng_live_url_parts_deleter(const bt_common_lttng_live_url_parts_deleter&) = delete;
+    bt_common_lttng_live_url_parts&
+    operator=(const bt_common_lttng_live_url_parts_deleter&) = delete;
+
+    ~bt_common_lttng_live_url_parts_deleter()
+    {
+        bt_common_destroy_lttng_live_url_parts(_mObj);
+    }
+
+private:
+    bt_common_lttng_live_url_parts *_mObj;
+};
+
 enum lttng_live_stream_state
 {
     /* This stream won't have data until some known time in the future. */
index 66605b10022cc66ceeb1cb352c357b52a0624aa3..924e5fba24caf66fc0337b2d94bc251b04b9d4a8 100644 (file)
@@ -229,6 +229,7 @@ static int parse_url(struct live_viewer_connection *viewer_connection)
 {
     char error_buf[256] = {0};
     struct bt_common_lttng_live_url_parts lttng_live_url_parts = {};
+    bt_common_lttng_live_url_parts_deleter partsDeleter {lttng_live_url_parts};
     int ret = -1;
 
     if (viewer_connection->url.empty()) {
@@ -265,7 +266,6 @@ static int parse_url(struct live_viewer_connection *viewer_connection)
     ret = 0;
 
 end:
-    bt_common_destroy_lttng_live_url_parts(&lttng_live_url_parts);
     return ret;
 }
 
This page took 0.026593 seconds and 4 git commands to generate.