Skip to content

Commit

Permalink
Make sure to always free response_bytes.
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Jan 8, 2024
1 parent ce6af2b commit 7773aee
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2474,9 +2474,12 @@ rmw_send_response(
allocator->state));
if (!response_bytes) {
RMW_SET_ERROR_MSG("failed allocate response message bytes");
allocator->deallocate(response_bytes, allocator->state);
return RMW_RET_ERROR;
}
auto free_response_bytes = rcpputils::make_scope_exit(
[response_bytes, allocator]() {
allocator->deallocate(response_bytes, allocator->state);
});

// Object that manages the raw buffer
eprosima::fastcdr::FastBuffer fastbuffer(response_bytes, max_data_length);
Expand All @@ -2491,7 +2494,6 @@ rmw_send_response(
ser,
service_data->response_type_support_impl))
{
allocator->deallocate(response_bytes, allocator->state);
return RMW_RET_ERROR;
}

Expand Down

0 comments on commit 7773aee

Please sign in to comment.