aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/reqrep
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-29 22:41:05 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-29 22:41:05 -0800
commit5d90b485fdb39cac7d1aac2ab8958ecd585ac69b (patch)
tree4e2917512ac9ed6348d8ccc23d68b9291cd059c0 /src/protocol/reqrep
parent541a53b857dc6e7c3ff5e642394369cf26bf4544 (diff)
downloadnng-5d90b485fdb39cac7d1aac2ab8958ecd585ac69b.tar.gz
nng-5d90b485fdb39cac7d1aac2ab8958ecd585ac69b.tar.bz2
nng-5d90b485fdb39cac7d1aac2ab8958ecd585ac69b.zip
Fix error handling during initialization.
Diffstat (limited to 'src/protocol/reqrep')
-rw-r--r--src/protocol/reqrep/req.c20
1 files changed, 15 insertions, 5 deletions
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);
}