mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-26 23:01:04 +08:00
Fix zmq crash when calling shutdown with a pending inproc socket connect
This commit is contained in:
parent
4e5843b8ff
commit
096007c574
@ -126,15 +126,20 @@ zmq::ctx_t::~ctx_t ()
|
||||
|
||||
int zmq::ctx_t::terminate ()
|
||||
{
|
||||
// Connect up any pending inproc connections, otherwise we will hang
|
||||
slot_sync.lock();
|
||||
|
||||
bool saveTerminating = terminating;
|
||||
terminating = false;
|
||||
|
||||
// Connect up any pending inproc connections, otherwise we will hang
|
||||
pending_connections_t copy = pending_connections;
|
||||
for (pending_connections_t::iterator p = copy.begin (); p != copy.end (); ++p) {
|
||||
zmq::socket_base_t *s = create_socket (ZMQ_PAIR);
|
||||
s->bind (p->first.c_str ());
|
||||
s->close ();
|
||||
}
|
||||
terminating = saveTerminating;
|
||||
|
||||
slot_sync.lock ();
|
||||
if (!starting) {
|
||||
|
||||
#ifdef HAVE_FORK
|
||||
|
@ -471,6 +471,27 @@ void test_unbind ()
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
void test_shutdown_during_pend ()
|
||||
{
|
||||
void *ctx = zmq_ctx_new ();
|
||||
assert (ctx);
|
||||
|
||||
// Connect first
|
||||
void *connectSocket = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (connectSocket);
|
||||
int rc = zmq_connect (connectSocket, "inproc://cbb");
|
||||
assert (rc == 0);
|
||||
|
||||
zmq_ctx_shutdown (ctx);
|
||||
|
||||
// Cleanup
|
||||
rc = zmq_close (connectSocket);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_ctx_term (ctx);
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
setup_test_environment ();
|
||||
@ -484,6 +505,7 @@ int main (void)
|
||||
test_identity ();
|
||||
test_connect_only ();
|
||||
test_unbind ();
|
||||
test_shutdown_during_pend ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user