diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index 9e686fcd44b..e984fc55cb2 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -262,11 +262,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; } @@ -275,11 +279,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; }