src.ctf.fs: use GMappedFileUP in build_index_from_idx_file
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 9 Jun 2022 19:51:18 +0000 (15:51 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 23 Aug 2022 16:06:16 +0000 (12:06 -0400)
Change-Id: I24d4cf509839923e704870953b6c9fb379cf1880
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8312
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/fs-src/data-stream-file.cpp

index 67ef4d8659a38d6479e0061b6c7987ff36c56ad3..8855cbe9674421884bb53419e6c3a4b4383b369e 100644 (file)
@@ -463,7 +463,7 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
     bt2_common::GCharUP basename;
     std::string index_basename;
     bt2_common::GCharUP index_file_path;
-    GMappedFile *mapped_file = NULL;
+    bt2_common::GMappedFileUP mapped_file;
     gsize filesize;
     const char *mmap_begin = NULL, *file_pos = NULL;
     const struct ctf_packet_index_file_hdr *header = NULL;
@@ -510,7 +510,7 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
     index_basename += ".idx";
 
     index_file_path.reset(g_build_filename(directory.get(), "index", index_basename.c_str(), NULL));
-    mapped_file = g_mapped_file_new(index_file_path.get(), FALSE, NULL);
+    mapped_file.reset(g_mapped_file_new(index_file_path.get(), FALSE, NULL));
     if (!mapped_file) {
         BT_CLOGD("Cannot create new mapped file %s", index_file_path.get());
         goto error;
@@ -521,7 +521,7 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
      * Traces with such large indexes have never been seen in the wild,
      * but this would need to be adjusted to support them.
      */
-    filesize = g_mapped_file_get_length(mapped_file);
+    filesize = g_mapped_file_get_length(mapped_file.get());
     if (filesize < sizeof(*header)) {
         BT_CLOGW("Invalid LTTng trace index file: "
                  "file size (%zu bytes) < header size (%zu bytes)",
@@ -529,10 +529,10 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
         goto error;
     }
 
-    mmap_begin = g_mapped_file_get_contents(mapped_file);
+    mmap_begin = g_mapped_file_get_contents(mapped_file.get());
     header = (struct ctf_packet_index_file_hdr *) mmap_begin;
 
-    file_pos = g_mapped_file_get_contents(mapped_file) + sizeof(*header);
+    file_pos = g_mapped_file_get_contents(mapped_file.get()) + sizeof(*header);
     if (be32toh(header->magic) != CTF_INDEX_MAGIC) {
         BT_CLOGW_STR("Invalid LTTng trace index: \"magic\" field validation failed");
         goto error;
@@ -640,9 +640,6 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
         goto error;
     }
 end:
-    if (mapped_file) {
-        g_mapped_file_unref(mapped_file);
-    }
     return index;
 error:
     index.reset();
This page took 0.026466 seconds and 5 git commands to generate.