From 5d90b485fdb39cac7d1aac2ab8958ecd585ac69b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 29 Dec 2016 22:41:05 -0800 Subject: Fix error handling during initialization. --- src/protocol/reqrep/req.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/protocol/reqrep') diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c index b0225e90..54ac7b11 100644 --- a/src/protocol/reqrep/req.c +++ b/src/protocol/reqrep/req.c @@ -121,7 +121,9 @@ nni_req_add_pipe(void *arg, nni_pipe *pipe, void **datap) nni_req_pipe *rp; int rv; - rp = nni_alloc(sizeof (*rp)); + if ((rp = nni_alloc(sizeof (*rp))) == NULL) { + return (NNG_ENOMEM); + } rp->pipe = pipe; rp->good = 0; rp->sigclose = 0; @@ -131,18 +133,26 @@ nni_req_add_pipe(void *arg, nni_pipe *pipe, void **datap) nni_mutex_enter(&req->mx); if ((rv = nni_thread_create(&rp->rthr, nni_req_receiver, rp)) != 0) { - nni_mutex_exit(&req->mx); - return (rv); + goto fail; } if ((rv = nni_thread_create(&rp->sthr, nni_req_sender, rp)) != 0) { - nni_mutex_exit(&req->mx); - return (rv); + goto fail; } rp->good = 1; nni_list_append(&req->pipes, rp); *datap = rp; nni_mutex_exit(&req->mx); return (0); +fail: + nni_mutex_exit(&req->mx); + if (rp->rthr) { + nni_thread_reap(rp->rthr); + } + if (rp->sthr) { + nni_thread_reap(rp->sthr); + } + nni_free(rp, sizeof (*rp)); + return (rv); } -- cgit v1.2.3-70-g09d2