src.ctf.fs: use GCharUP in build_index_from_idx_file
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Jul 2022 21:20:07 +0000 (17:20 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 23 Aug 2022 16:06:16 +0000 (12:06 -0400)
Change-Id: Ifb4e1b3ac7d484af2d570d75cff21e310f752add
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8309
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/fs-src/data-stream-file.cpp

index c2e5266ca5d5ba87c2378adb6055cf6e50de16db..4d3247399405029c8201eb439432fa69e109b6ed 100644 (file)
@@ -459,10 +459,10 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
                                                      struct ctf_msg_iter *msg_iter)
 {
     int ret;
-    gchar *directory = NULL;
-    gchar *basename = NULL;
+    bt2_common::GCharUP directory;
+    bt2_common::GCharUP basename;
     GString *index_basename = NULL;
-    gchar *index_file_path = NULL;
+    bt2_common::GCharUP index_file_path;
     GMappedFile *mapped_file = NULL;
     gsize filesize;
     const char *mmap_begin = NULL, *file_pos = NULL;
@@ -494,29 +494,29 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
     }
 
     /* Look for index file in relative path index/name.idx. */
-    basename = g_path_get_basename(ds_file->file->path.c_str());
+    basename.reset(g_path_get_basename(ds_file->file->path.c_str()));
     if (!basename) {
         BT_CLOGE("Cannot get the basename of datastream file %s", ds_file->file->path.c_str());
         goto error;
     }
 
-    directory = g_path_get_dirname(ds_file->file->path.c_str());
+    directory.reset(g_path_get_dirname(ds_file->file->path.c_str()));
     if (!directory) {
         BT_CLOGE("Cannot get dirname of datastream file %s", ds_file->file->path.c_str());
         goto error;
     }
 
-    index_basename = g_string_new(basename);
+    index_basename = g_string_new(basename.get());
     if (!index_basename) {
         BT_CLOGE_STR("Cannot allocate index file basename string");
         goto error;
     }
 
     g_string_append(index_basename, ".idx");
-    index_file_path = g_build_filename(directory, "index", index_basename->str, NULL);
-    mapped_file = g_mapped_file_new(index_file_path, FALSE, NULL);
+    index_file_path.reset(g_build_filename(directory.get(), "index", index_basename->str, NULL));
+    mapped_file = g_mapped_file_new(index_file_path.get(), FALSE, NULL);
     if (!mapped_file) {
-        BT_CLOGD("Cannot create new mapped file %s", index_file_path);
+        BT_CLOGD("Cannot create new mapped file %s", index_file_path.get());
         goto error;
     }
 
@@ -644,9 +644,6 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
         goto error;
     }
 end:
-    g_free(directory);
-    g_free(basename);
-    g_free(index_file_path);
     if (index_basename) {
         g_string_free(index_basename, TRUE);
     }
This page took 0.032729 seconds and 5 git commands to generate.