From 7cfc81b40bbe7fef0ceae37a18e8c319fc0c4ba7 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Wed, 7 Feb 2024 14:57:17 -0500 Subject: [PATCH] Switch to RAII for saved_msg_data. Signed-off-by: Chris Lalancette --- rmw_zenoh_cpp/src/detail/rmw_data_types.cpp | 6 +++++- rmw_zenoh_cpp/src/detail/rmw_data_types.hpp | 2 ++ rmw_zenoh_cpp/src/rmw_zenoh.cpp | 1 - 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp b/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp index 99eb3fd9..5fc8e65d 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp @@ -31,6 +31,11 @@ saved_msg_data::saved_msg_data(zc_owned_payload_t p, uint64_t recv_ts, const uin memcpy(publisher_gid, pub_gid, 16); } +saved_msg_data::~saved_msg_data() +{ + z_drop(z_move(payload)); +} + void rmw_subscription_data_t::attach_condition(std::condition_variable * condition_variable) { std::lock_guard lock(condition_mutex_); @@ -92,7 +97,6 @@ void rmw_subscription_data_t::add_new_message( // queue if it is non-empty. if (!message_queue_.empty()) { std::unique_ptr old = std::move(message_queue_.front()); - z_drop(z_move(old->payload)); message_queue_.pop_front(); } } diff --git a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp index 0100211f..e9bcfac9 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp +++ b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp @@ -111,6 +111,8 @@ struct saved_msg_data { explicit saved_msg_data(zc_owned_payload_t p, uint64_t recv_ts, const uint8_t pub_gid[16]); + ~saved_msg_data(); + zc_owned_payload_t payload; uint64_t recv_timestamp; uint8_t publisher_gid[16]; diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 4c21f5cc..b956572a 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -1578,7 +1578,6 @@ static rmw_ret_t __rmw_take( } *taken = true; - z_drop(&msg_data->payload); // TODO(clalancette): fill in source_timestamp message_info->source_timestamp = 0;