diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index 26c02d916b1..9f07fe17324 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -265,11 +265,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; } @@ -278,11 +282,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; }