From fb36128c20efd34067bbcee4f78289671dcd9bd1 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Tue, 4 Jul 2017 18:30:30 +0200 Subject: lib: Handle errors when creating cdap_req structs --- src/lib/cdap_req.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/cdap_req.c b/src/lib/cdap_req.c index bb11dbf6..a89d6b2a 100644 --- a/src/lib/cdap_req.c +++ b/src/lib/cdap_req.c @@ -48,12 +48,23 @@ struct cdap_req * cdap_req_create(int fd, creq->data.data = NULL; creq->data.len = 0; + if (pthread_mutex_init(&creq->lock, NULL)) { + free(creq); + return NULL; + } + pthread_condattr_init(&cattr); #ifndef __APPLE__ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK); #endif - pthread_cond_init(&creq->cond, &cattr); - pthread_mutex_init(&creq->lock, NULL); + if (pthread_cond_init(&creq->cond, &cattr)) { + pthread_condattr_destroy(&cattr); + pthread_mutex_destroy(&creq->lock); + free(creq); + return NULL; + } + + pthread_condattr_destroy(&cattr); list_head_init(&creq->next); -- cgit v1.2.3