diff --git a/src/ipc_listener.cpp b/src/ipc_listener.cpp index 0033eef4..9aa5005b 100644 --- a/src/ipc_listener.cpp +++ b/src/ipc_listener.cpp @@ -145,7 +145,7 @@ int zmq::ipc_listener_t::set_address (const char *addr_) // Bind the socket to the file path. rc = bind (s, address.addr (), address.addrlen ()); if (rc != 0) - return -1; + goto error; filename.assign(addr_); has_file = true; @@ -153,10 +153,16 @@ int zmq::ipc_listener_t::set_address (const char *addr_) // Listen for incomming connections. rc = listen (s, options.backlog); if (rc != 0) - return -1; + goto error; socket->monitor_event (ZMQ_EVENT_LISTENING, addr_, s); return 0; + +error: + int err = errno; + close (); + errno = err; + return -1; } int zmq::ipc_listener_t::close () diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index 5fbe3cd9..32a27ae7 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -208,11 +208,11 @@ int zmq::tcp_listener_t::set_address (const char *addr_) #ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno (WSAGetLastError ()); - return -1; + goto error; } #else if (rc != 0) - return -1; + goto error; #endif // Listen for incomming connections. @@ -220,15 +220,21 @@ int zmq::tcp_listener_t::set_address (const char *addr_) #ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno (WSAGetLastError ()); - return -1; + goto error; } #else if (rc != 0) - return -1; + goto error; #endif socket->monitor_event (ZMQ_EVENT_LISTENING, addr_, s); return 0; + +error: + int err = errno; + close (); + errno = err; + return -1; } zmq::fd_t zmq::tcp_listener_t::accept ()