Commit 75d67286 authored by Martin Hurton's avatar Martin Hurton

{tcp|ipc}_listener: close socket when set_address () fails

parent a9507cc2
......@@ -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 ()
......
......@@ -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 ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment