diff --git a/easy_profiler_core/easy_socket.cpp b/easy_profiler_core/easy_socket.cpp index bfb1e5c..350a51b 100644 --- a/easy_profiler_core/easy_socket.cpp +++ b/easy_profiler_core/easy_socket.cpp @@ -123,8 +123,10 @@ void EasySocket::flush() if (m_socket) closeSocket(m_socket); - if (m_replySocket != m_socket) + if (m_replySocket != m_socket && m_replySocket != 0) { + // we do not need to close uninitialized reply socket closeSocket(m_replySocket); + } #if defined(_WIN32) m_socket = 0; @@ -157,6 +159,9 @@ void EasySocket::checkResult(int result) #if !defined(_WIN32) case SOCK_BROKEN_PIPE: case SOCK_ENOENT: +#endif +#if defined (__APPLE__) + case ECONNREFUSED: #endif m_state = ConnectionState::Disconnected; break; diff --git a/profiler_gui/main_window.cpp b/profiler_gui/main_window.cpp index b9ea501..498a983 100644 --- a/profiler_gui/main_window.cpp +++ b/profiler_gui/main_window.cpp @@ -2536,11 +2536,9 @@ void MainWindow::onConnectClicked(bool) if (!m_listener.connect(address.toStdString().c_str(), port, reply)) { Dialog::warning(this, "Warning", QString("Cannot connect to %1").arg(address), QMessageBox::Close); - if (EASY_GLOBALS.connected) - { - m_listener.closeSocket(); - setDisconnected(false); - } + // we need to close socket everytime on failed connection + m_listener.closeSocket(); + setDisconnected(false); if (!isSameAddress) {