summaryrefslogtreecommitdiff
path: root/ecp
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-05-03 00:07:34 +0200
committerUros Majstorovic <majstor@majstor.org>2024-05-03 00:07:34 +0200
commitbda8ca03b59ac130b264f7ad39a10bb540e93a0a (patch)
tree6c1028238e16617795b567afbe43504f02cc4eba /ecp
parent3e9b350110357e7b9555ad910986dc53edf554ad (diff)
prevented possible race condition with conn open / close
Diffstat (limited to 'ecp')
-rw-r--r--ecp/src/ecp/core.c16
1 files changed, 8 insertions, 8 deletions
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;
}