src.ctf.fs: make ctf_fs_make_port_name return a GCharUP
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 11 Dec 2023 18:26:39 +0000 (13:26 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Make ctf_fs_make_port_name return a GCharUP, which then helps use
automatic memory management in the callers.

Change-Id: I9191ddbafa86a4788fc5e16fc561dfda7696cfa6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8166
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12267
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/fs.cpp
src/plugins/ctf/fs-src/fs.hpp
src/plugins/ctf/fs-src/query.cpp

index db8be9962ee943034631db9cb4a9a5496ffdbf4e..968c451d3b9397040d14969a6edec2680726c7ed 100644 (file)
@@ -362,7 +362,7 @@ void ctf_fs_finalize(bt_self_component_source *component)
         bt_self_component_source_as_self_component(component)));
 }
 
-gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
+bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
 {
     GString *name = g_string_new(NULL);
 
@@ -403,7 +403,7 @@ gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
         g_string_append_printf(name, " | %s", ds_file_info->path->str);
     }
 
-    return g_string_free(name, FALSE);
+    return bt2c::GCharUP {g_string_free(name, FALSE)};
 }
 
 static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
@@ -412,20 +412,19 @@ static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
 {
     int ret = 0;
     struct ctf_fs_port_data *port_data = NULL;
-    gchar *port_name;
 
-    port_name = ctf_fs_make_port_name(ds_file_group);
+    bt2c::GCharUP port_name = ctf_fs_make_port_name(ds_file_group);
     if (!port_name) {
         goto error;
     }
 
-    BT_CPPLOGI_SPEC(ctf_fs->logger, "Creating one port named `{}`", port_name);
+    BT_CPPLOGI_SPEC(ctf_fs->logger, "Creating one port named `{}`", port_name.get());
 
     /* Create output port for this file */
     port_data = new ctf_fs_port_data;
     port_data->ctf_fs = ctf_fs;
     port_data->ds_file_group = ds_file_group;
-    ret = bt_self_component_source_add_output_port(self_comp_src, port_name, port_data, NULL);
+    ret = bt_self_component_source_add_output_port(self_comp_src, port_name.get(), port_data, NULL);
     if (ret) {
         goto error;
     }
@@ -438,8 +437,6 @@ error:
     ret = -1;
 
 end:
-    g_free(port_name);
-
     port_data_destroy(port_data);
     return ret;
 }
index 405bb145c6e8fb4792c73588f3cd660e7294f483..54a8ec0234df248c846f992f111c684c8c0d9cb9 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <babeltrace2/babeltrace.h>
 
+#include "cpp-common/bt2c/glib-up.hpp"
 #include "cpp-common/bt2c/logging.hpp"
 
 #include "metadata.hpp"
@@ -281,10 +282,8 @@ bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
 
 /*
  * Generate the port name to be used for a given data stream file group.
- *
- * The result must be freed using g_free by the caller.
  */
 
-gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
+bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
 
 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */
index 1e87697c9b1585de296d31fac27736d10b871ff0..488675038e7c925f876f748470d61421ff820197 100644 (file)
@@ -196,7 +196,7 @@ static int populate_stream_info(struct ctf_fs_ds_file_group *group, bt_value *gr
     int ret = 0;
     bt_value_map_insert_entry_status insert_status;
     struct ctf_fs_ds_index_entry *first_ds_index_entry, *last_ds_index_entry;
-    gchar *port_name = NULL;
+    bt2c::GCharUP port_name;
 
     /*
      * Since each `struct ctf_fs_ds_file_group` has a sorted array of
@@ -238,14 +238,13 @@ static int populate_stream_info(struct ctf_fs_ds_file_group *group, bt_value *gr
         goto end;
     }
 
-    insert_status = bt_value_map_insert_string_entry(group_info, "port-name", port_name);
+    insert_status = bt_value_map_insert_string_entry(group_info, "port-name", port_name.get());
     if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
         ret = -1;
         goto end;
     }
 
 end:
-    g_free(port_name);
     return ret;
 }
 
This page took 0.02887 seconds and 4 git commands to generate.