Skip to content

Commit

Permalink
Use a scope_exit to drop the keystr.
Browse files Browse the repository at this point in the history
This just makes sure we always clean it up.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Jan 8, 2024
1 parent a414685 commit 177451a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions rmw_zenoh_cpp/src/detail/rmw_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <mutex>
#include <utility>

#include "rcpputils/scope_exit.hpp"
#include "rcutils/logging_macros.h"

#include "rmw_data_types.hpp"
Expand All @@ -34,6 +35,10 @@ void sub_data_handler(
void * data)
{
z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr);
auto drop_keystr = rcpputils::make_scope_exit(
[&keystr]() {
z_drop(z_move(keystr));
});

auto sub_data = static_cast<rmw_subscription_data_t *>(data);
if (sub_data == nullptr) {
Expand Down Expand Up @@ -74,8 +79,6 @@ void sub_data_handler(
sub_data->condition->notify_one();
}
}

z_drop(z_move(keystr));
}


Expand All @@ -93,6 +96,10 @@ void service_data_handler(const z_query_t * query, void * data)
"[service_data_handler] triggered"
);
z_owned_str_t keystr = z_keyexpr_to_string(z_query_keyexpr(query));
auto drop_keystr = rcpputils::make_scope_exit(
[&keystr]() {
z_drop(z_move(keystr));
});

rmw_service_data_t * service_data = static_cast<rmw_service_data_t *>(data);
if (service_data == nullptr) {
Expand All @@ -102,7 +109,6 @@ void service_data_handler(const z_query_t * query, void * data)
"service for %s",
z_loan(keystr)
);
z_drop(z_move(keystr));
return;
}

Expand All @@ -121,8 +127,6 @@ void service_data_handler(const z_query_t * query, void * data)
service_data->condition->notify_one();
}
}

z_drop(z_move(keystr));
}

//==============================================================================
Expand Down

0 comments on commit 177451a

Please sign in to comment.