diff --git a/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp b/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp index 12095bea87..560fdcc96e 100644 --- a/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp +++ b/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp @@ -163,25 +163,29 @@ cxx::expected UnixDomainSocket::unlinkIfExists(const NoPa cxx::expected UnixDomainSocket::closeFileDescriptor() noexcept { - auto closeCall = - cxx::makeSmartC(closePlatformFileHandle, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_sockfd); - - if (!closeCall.hasErrors()) + if (m_sockfd != INVALID_FD) { - if (IpcChannelSide::SERVER == m_channelSide) + auto closeCall = cxx::makeSmartC( + closePlatformFileHandle, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_sockfd); + + if (!closeCall.hasErrors()) { - unlink(m_sockAddr.sun_path); - } + if (IpcChannelSide::SERVER == m_channelSide) + { + unlink(m_sockAddr.sun_path); + } - m_sockfd = INVALID_FD; - m_isInitialized = false; + m_sockfd = INVALID_FD; + m_isInitialized = false; - return cxx::success(); - } - else - { - return createErrorFromErrnum(closeCall.getErrNum()); + return cxx::success(); + } + else + { + return createErrorFromErrnum(closeCall.getErrNum()); + } } + return cxx::success<>(); } cxx::expected UnixDomainSocket::destroy() noexcept