diff options
author | Pieter Hintjens <ph@imatix.com> | 2012-03-22 11:03:32 -0500 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-03-24 09:20:00 +0100 |
commit | 153eaae2dbc816c4edee49666202b3d1172f0b34 (patch) | |
tree | c550527e0437fdad2d1443870dff933a5dec2e52 | |
parent | 5f9e3a26ee4ee894e39e8964efbd86bac87e2eec (diff) |
Fixed issue LIBZMQ-345 - race condition in ctx.socket/term allows segfault
-rw-r--r-- | src/ctx.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/ctx.cpp b/src/ctx.cpp index 6fb2b36..22c4908 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -83,11 +83,11 @@ xs::ctx_t::~ctx_t () int xs::ctx_t::terminate () { + slot_sync.lock (); if (!starting) { // Check whether termination was already underway, but interrupted and now // restarted. - slot_sync.lock (); bool restarted = terminating; terminating = true; slot_sync.unlock (); @@ -115,8 +115,8 @@ int xs::ctx_t::terminate () xs_assert (cmd.type == command_t::done); slot_sync.lock (); xs_assert (sockets.empty ()); - slot_sync.unlock (); } + slot_sync.unlock (); // Deallocate the resources. delete this; @@ -154,6 +154,7 @@ int xs::ctx_t::setctxopt (int option_, const void *optval_, size_t optvallen_) xs::socket_base_t *xs::ctx_t::create_socket (int type_) { + slot_sync.lock (); if (unlikely (starting)) { starting = false; @@ -194,8 +195,6 @@ xs::socket_base_t *xs::ctx_t::create_socket (int type_) } } - slot_sync.lock (); - // Once xs_term() was called, we can't create new sockets. if (terminating) { slot_sync.unlock (); |