From fbd128122c07c6a0287bde19e2bfc8ee577396ad Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 5 Dec 2023 05:52:55 +0000 Subject: [PATCH] src.ctf.fs: use GMappedFileUP in build_index_from_idx_file Change-Id: I24d4cf509839923e704870953b6c9fb379cf1880 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8312 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12338 Tested-by: jenkins --- src/plugins/ctf/fs-src/data-stream-file.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/plugins/ctf/fs-src/data-stream-file.cpp b/src/plugins/ctf/fs-src/data-stream-file.cpp index 77305a38..f8ea1d97 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.cpp +++ b/src/plugins/ctf/fs-src/data-stream-file.cpp @@ -450,7 +450,7 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f bt2c::GCharUP basename; std::string index_basename; bt2c::GCharUP index_file_path; - GMappedFile *mapped_file = NULL; + bt2c::GMappedFileUP mapped_file; gsize filesize; const char *mmap_begin = NULL, *file_pos = NULL; const struct ctf_packet_index_file_hdr *header = NULL; @@ -498,7 +498,7 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f index_basename = fmt::format("{}.idx", basename.get()); 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_CPPLOGD_SPEC(ds_file->logger, "Cannot create new mapped file {}", index_file_path.get()); goto error; @@ -509,7 +509,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_CPPLOGW_SPEC(ds_file->logger, "Invalid LTTng trace index file: " @@ -518,10 +518,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_CPPLOGW_STR_SPEC(ds_file->logger, "Invalid LTTng trace index: \"magic\" field validation failed"); @@ -639,9 +639,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(); -- 2.34.1