From 153eaae2dbc816c4edee49666202b3d1172f0b34 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Thu, 22 Mar 2012 11:03:32 -0500 Subject: Fixed issue LIBZMQ-345 - race condition in ctx.socket/term allows segfault --- src/ctx.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/ctx.cpp') 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 (); -- cgit v1.2.3