From 89f88383db49cadfb3ad68e5a1ccae0de77a98e6 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 9 Dec 2023 14:37:28 +0000 Subject: [PATCH] src.ctf.fs: make ctf_fs_ds_file_create return a unique_ptr Introduce ctf_fs_ds_file::UP, make ctf_fs_ds_file_create return it. Change-Id: I0139e9504d65425bf53fb21a5b81a4e48da4fe4e Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8268 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12306 Tested-by: jenkins --- src/plugins/ctf/fs-src/data-stream-file.cpp | 18 +++++++----------- src/plugins/ctf/fs-src/data-stream-file.hpp | 6 ++++-- src/plugins/ctf/fs-src/fs.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/plugins/ctf/fs-src/data-stream-file.cpp b/src/plugins/ctf/fs-src/data-stream-file.cpp index 9f5c5410..c3114a69 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.cpp +++ b/src/plugins/ctf/fs-src/data-stream-file.cpp @@ -329,7 +329,8 @@ ctf_fs_ds_group_medops_set_file(struct ctf_fs_ds_group_medops_data *data, /* Create the new file. */ data->file = ctf_fs_ds_file_create(data->ds_file_group->ctf_fs_trace, data->ds_file_group->stream, - index_entry->path, data->logger); + index_entry->path, data->logger) + .release(); if (!data->file) { BT_CPPLOGE_APPEND_CAUSE_SPEC(data->logger, "failed to create ctf_fs_ds_file."); status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; @@ -811,17 +812,13 @@ error: goto end; } -struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, - bt2::Stream::Shared stream, const char *path, - const bt2c::Logger& parentLogger) +ctf_fs_ds_file::UP ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, + bt2::Stream::Shared stream, const char *path, + const bt2c::Logger& parentLogger) { int ret; + auto ds_file = bt2s::make_unique(parentLogger); size_t offset_align; - ctf_fs_ds_file *ds_file = new ctf_fs_ds_file {parentLogger}; - - if (!ds_file) { - goto error; - } ds_file->file = ctf_fs_file_create(parentLogger); if (!ds_file->file) { @@ -843,8 +840,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, error: /* Do not touch "borrowed" file. */ - delete ds_file; - ds_file = NULL; + ds_file.reset(); end: return ds_file; diff --git a/src/plugins/ctf/fs-src/data-stream-file.hpp b/src/plugins/ctf/fs-src/data-stream-file.hpp index 8ffc670d..71c31e23 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.hpp +++ b/src/plugins/ctf/fs-src/data-stream-file.hpp @@ -35,6 +35,8 @@ struct ctf_fs_ds_file_info struct ctf_fs_ds_file { + using UP = std::unique_ptr; + explicit ctf_fs_ds_file(const bt2c::Logger& parentLogger) : logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS"} { @@ -146,8 +148,8 @@ struct ctf_fs_ds_file_group ctf_fs_ds_index::UP index; }; -struct ctf_fs_ds_file *ctf_fs_ds_file_create(ctf_fs_trace *ctf_fs_trace, bt2::Stream::Shared stream, - const char *path, const bt2c::Logger& logger); +ctf_fs_ds_file::UP ctf_fs_ds_file_create(ctf_fs_trace *ctf_fs_trace, bt2::Stream::Shared stream, + const char *path, const bt2c::Logger& logger); ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file, struct ctf_fs_ds_file_info *ds_file_info, diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index 4405ca2f..1b76a79f 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -524,7 +524,8 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const * stream file. */ ds_file = - ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, path, ctf_fs_trace->logger); + ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, path, ctf_fs_trace->logger) + .release(); if (!ds_file) { goto error; } @@ -1128,7 +1129,8 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace, BT_ASSERT(index_entry->path); ds_file = ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, index_entry->path, - ctf_fs_trace->logger); + ctf_fs_trace->logger) + .release(); if (!ds_file) { BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to create a ctf_fs_ds_file"); ret = -1; -- 2.34.1