From bda8ca03b59ac130b264f7ad39a10bb540e93a0a Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 3 May 2024 00:07:34 +0200 Subject: prevented possible race condition with conn open / close --- ecp/src/ecp/core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ecp/src') diff --git a/ecp/src/ecp/core.c b/ecp/src/ecp/core.c index 3e4aae1..69743fe 100644 --- a/ecp/src/ecp/core.c +++ b/ecp/src/ecp/core.c @@ -1091,36 +1091,36 @@ int ecp_conn_insert_gc(ECPConnection *conn) { ECPSocket *sock = conn->sock; int rv = ECP_OK; - rv = ecp_conn_refcount_inc(conn); - if (rv) return rv; - #ifdef ECP_WITH_PTHREAD pthread_mutex_lock(&sock->conn_table.mutex_gc); #endif + rv = ecp_conn_refcount_inc(conn); + if (!rv) { #ifdef ECP_WITH_HTABLE - rv = ecp_ht_insert(sock->conn_table.keys_gc, &conn->remote.key_perma.public, conn); + rv = ecp_ht_insert(sock->conn_table.keys_gc, &conn->remote.key_perma.public, conn); + if (rv) ecp_conn_refcount_dec(conn); #else /* ECP_WITH_HTABLE */ #ifdef ECP_WITH_PTHREAD - pthread_mutex_lock(&conn->mutex); + pthread_mutex_lock(&conn->mutex); #endif - _ecp_conn_push_gct(conn); + _ecp_conn_push_gct(conn); #ifdef ECP_WITH_PTHREAD - pthread_mutex_unlock(&conn->mutex); + pthread_mutex_unlock(&conn->mutex); #endif #endif /* ECP_WITH_HTABLE */ + } #ifdef ECP_WITH_PTHREAD pthread_mutex_unlock(&sock->conn_table.mutex_gc); #endif - if (rv) ecp_conn_refcount_dec(conn); return rv; } -- cgit v1.2.3