From ac80ef7c3b1caa2f1fe3b093bef825363675bcb3 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 26 Jun 2017 18:27:06 -0700 Subject: More race condition fixes. --- src/core/endpt.c | 12 ++++++++---- src/core/panic.c | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/endpt.c b/src/core/endpt.c index ab0d8cb9..74bd0314 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -253,7 +253,9 @@ nni_ep_connect(nni_ep *ep) nni_pipe_remove(pipe); return (rv); } + nni_mtx_lock(&ep->ep_mtx); ep->ep_pipe = pipe; + nni_mtx_unlock(&ep->ep_mtx); return (0); } @@ -277,17 +279,19 @@ nni_ep_pipe_add(nni_ep *ep, nni_pipe *pipe) void nni_ep_pipe_remove(nni_ep *ep, nni_pipe *pipe) { - if ((ep != NULL) && (nni_list_active(&ep->ep_pipes, pipe))) { - nni_mtx_lock(&ep->ep_mtx); + if (ep == NULL) { + return; + } + nni_mtx_lock(&ep->ep_mtx); + if (nni_list_active(&ep->ep_pipes, pipe)) { nni_list_remove(&ep->ep_pipes, pipe); if (ep->ep_pipe == pipe) { ep->ep_pipe = NULL; } nni_cv_wake(&ep->ep_cv); - - nni_mtx_unlock(&ep->ep_mtx); } + nni_mtx_unlock(&ep->ep_mtx); } diff --git a/src/core/panic.c b/src/core/panic.c index 2205779f..b3d64dc3 100644 --- a/src/core/panic.c +++ b/src/core/panic.c @@ -55,10 +55,12 @@ nni_panic(const char *fmt, ...) va_list va; va_start(va, fmt); - (void) snprintf(fbuf, sizeof (fbuf), "panic: %s", fmt); - (void) vsnprintf(buf, sizeof (buf), fbuf, va); + (void) vsnprintf(fbuf, sizeof (fbuf), fmt, va); va_end(va); + + (void) snprintf(buf, sizeof (buf), "panic: %s", fbuf); + nni_println(buf); nni_println("This message is indicative of a BUG."); nni_println("Report this at http://github.com/nanomsg/nanomsg"); -- cgit v1.2.3-70-g09d2