diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 45163813..4c21f5cc 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -82,6 +81,8 @@ namespace z_owned_keyexpr_t ros_topic_name_to_zenoh_key( const char * const topic_name, size_t domain_id, rcutils_allocator_t * allocator) { + std::string d = std::to_string(domain_id); + size_t start_offset = 0; size_t topic_name_len = strlen(topic_name); size_t end_offset = topic_name_len; @@ -97,18 +98,17 @@ z_owned_keyexpr_t ros_topic_name_to_zenoh_key( } } - std::stringstream domain_ss; - domain_ss << domain_id; char * stripped_topic_name = rcutils_strndup( &topic_name[start_offset], end_offset - start_offset, *allocator); if (stripped_topic_name == nullptr) { return z_keyexpr_null(); } - z_owned_keyexpr_t keyexpr = z_keyexpr_join( - z_keyexpr(domain_ss.str().c_str()), z_keyexpr(stripped_topic_name)); + + z_owned_keyexpr_t ret = z_keyexpr_join(z_keyexpr(d.c_str()), z_keyexpr(stripped_topic_name)); + allocator->deallocate(stripped_topic_name, allocator->state); - return keyexpr; + return ret; } //==============================================================================