src.ctf.fs: use std::string in set_trace_name
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 5 Dec 2023 05:19:53 +0000 (05:19 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Change-Id: Ib44748ebda40b197d5ef0ca20d23b55496c3e918
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8291
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12328
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/fs.cpp

index ed98c9619178454637e020ffc743b764dd7ade78..b915c8b444ca936c7ed4199fc4ddf3e4f28ad560 100644 (file)
@@ -673,18 +673,11 @@ end:
     return ret;
 }
 
-static int set_trace_name(bt_trace *trace, const char *name_suffix, const bt2c::Logger& logger)
+static int set_trace_name(bt_trace *trace, const char *name_suffix)
 {
     int ret = 0;
     const bt_value *val;
-    GString *name;
-
-    name = g_string_new(NULL);
-    if (!name) {
-        BT_CPPLOGE_STR_SPEC(logger, "Failed to allocate a GString.");
-        ret = -1;
-        goto end;
-    }
+    std::string name;
 
     /*
      * Check if we have a trace environment string value named `hostname`.
@@ -692,18 +685,18 @@ static int set_trace_name(bt_trace *trace, const char *name_suffix, const bt2c::
      */
     val = bt_trace_borrow_environment_entry_value_by_name_const(trace, "hostname");
     if (val && bt_value_is_string(val)) {
-        g_string_append(name, bt_value_string_get(val));
+        name += bt_value_string_get(val);
 
         if (name_suffix) {
-            g_string_append_c(name, G_DIR_SEPARATOR);
+            name += G_DIR_SEPARATOR;
         }
     }
 
     if (name_suffix) {
-        g_string_append(name, name_suffix);
+        name += name_suffix;
     }
 
-    ret = bt_trace_set_name(trace, name->str);
+    ret = bt_trace_set_name(trace, name.c_str());
     if (ret) {
         goto end;
     }
@@ -711,10 +704,6 @@ static int set_trace_name(bt_trace *trace, const char *name_suffix, const bt2c::
     goto end;
 
 end:
-    if (name) {
-        g_string_free(name, TRUE);
-    }
-
     return ret;
 }
 
@@ -750,7 +739,7 @@ static ctf_fs_trace::UP ctf_fs_trace_create(const char *path, const char *name,
             goto error;
         }
 
-        ret = set_trace_name(ctf_fs_trace->trace->libObjPtr(), name, ctf_fs_trace->logger);
+        ret = set_trace_name(ctf_fs_trace->trace->libObjPtr(), name);
         if (ret) {
             goto error;
         }
This page took 0.025927 seconds and 4 git commands to generate.