diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index f9cd60425e3..674c657bc7d 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -266,11 +266,15 @@ Locator TCPTransportInterface::remote_endpoint_to_locator( { Locator locator; asio::error_code ec; - endpoint_to_locator(channel->remote_endpoint(ec), locator); + auto endpoint = channel->remote_endpoint(ec); if (ec) { LOCATOR_INVALID(locator); } + else + { + endpoint_to_locator(endpoint, locator); + } return locator; } @@ -279,11 +283,15 @@ Locator TCPTransportInterface::local_endpoint_to_locator( { Locator locator; asio::error_code ec; - endpoint_to_locator(channel->local_endpoint(ec), locator); + auto endpoint = channel->local_endpoint(ec); if (ec) { LOCATOR_INVALID(locator); } + else + { + endpoint_to_locator(endpoint, locator); + } return locator; }