From 391cc397d8b8e1b6a296337feb00f591b9c6a571 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 9 Jan 2024 20:27:22 +0000 Subject: [PATCH] Remember to free request_bytes. Signed-off-by: Chris Lalancette --- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index f8c38509..b5d216c2 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -1954,9 +1954,12 @@ rmw_send_request( allocator->state)); if (!request_bytes) { RMW_SET_ERROR_MSG("failed allocate request message bytes"); - allocator->deallocate(request_bytes, allocator->state); return RMW_RET_ERROR; } + auto free_request_bytes = rcpputils::make_scope_exit( + [request_bytes, allocator]() { + allocator->deallocate(request_bytes, allocator->state); + }); // Object that manages the raw buffer eprosima::fastcdr::FastBuffer fastbuffer(request_bytes, max_data_length); @@ -1971,7 +1974,6 @@ rmw_send_request( ser, client_data->request_type_support_impl)) { - allocator->deallocate(request_bytes, allocator->state); return RMW_RET_ERROR; }