From 3f7d65efeb9866966a579f3708993c5bd6da6163 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 5 Dec 2023 05:19:53 +0000 Subject: [PATCH] src.ctf.fs: use std::string in set_trace_name Change-Id: Ib44748ebda40b197d5ef0ca20d23b55496c3e918 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8291 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12328 Tested-by: jenkins --- src/plugins/ctf/fs-src/fs.cpp | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index ed98c961..b915c8b4 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -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; } -- 2.34.1