From 5426124dc79e66be358b29a8990f8df78367b86e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 3 Feb 2023 20:28:29 +0100 Subject: [PATCH] rspro_server: Handle ipa_server_link_open() error case >>> CID 307530: Error handling issues (CHECKED_RETURN) >>> Calling "ipa_server_link_open" without checking return value (as is done elsewhere 4 out of 5 times). while at it, also add a missing pthread_rwlock_destroy() call which was missing in the existing ipa_server_link_create() error path. Closes: CID#307530 Change-Id: Ic32d53a236b80711651fb4ee196ac3b95148e61f --- src/server/rspro_server.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/server/rspro_server.c b/src/server/rspro_server.c index 550179d..da27a2d 100644 --- a/src/server/rspro_server.c +++ b/src/server/rspro_server.c @@ -844,6 +844,7 @@ struct rspro_server *rspro_server_create(void *ctx, const char *host, uint16_t p { struct rspro_server *srv = talloc_zero(ctx, struct rspro_server); + int rc; OSMO_ASSERT(srv); pthread_rwlock_init(&srv->rwlock, NULL); @@ -854,14 +855,22 @@ struct rspro_server *rspro_server_create(void *ctx, const char *host, uint16_t p pthread_rwlock_unlock(&srv->rwlock); srv->link = ipa_server_link_create(ctx, NULL, host, port, accept_cb, srv); - if (!srv->link) { - talloc_free(srv); - return NULL; - } + if (!srv->link) + goto out_free; - ipa_server_link_open(srv->link); + rc = ipa_server_link_open(srv->link); + if (rc < 0) + goto out_destroy; return srv; + +out_destroy: + ipa_server_link_destroy(srv->link); +out_free: + pthread_rwlock_destroy(&srv->rwlock); + talloc_free(srv); + + return NULL; } void rspro_server_destroy(struct rspro_server *srv)