diff options
-rw-r--r-- | ecp/src/ecp/vconn/vconn.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/ecp/src/ecp/vconn/vconn.c b/ecp/src/ecp/vconn/vconn.c index f8dc5df..2f3f1b0 100644 --- a/ecp/src/ecp/vconn/vconn.c +++ b/ecp/src/ecp/vconn/vconn.c @@ -69,25 +69,31 @@ static int insert_key_next(ECPVConnInb *vconn, unsigned char c_idx, ecp_ecdh_pub static ssize_t handle_next(ECPConnection *conn, unsigned char *msg, size_t msg_size, ECP2Buffer *bufs) { ECPVConnInb *vconn = (ECPVConnInb *)conn; ECPSocket *sock = conn->sock; - int is_open; + int rv = ECP_OK; if (msg_size < ECP_SIZE_ECDH_PUB) return ECP_ERR_SIZE; if (ecp_conn_is_outb(conn)) return ECP_ERR; - if (vconn->next) return ECP_ERR_NEXT; - #ifdef ECP_WITH_PTHREAD pthread_mutex_lock(&sock->conn_table.mutex); #endif - vconn->next = ecp_ht_search(sock->conn_table.keys, (ecp_ecdh_public_t *)msg); - if (vconn->next) ecp_conn_refcount_inc(vconn->next); + if (vconn->next == NULL) { + vconn->next = ecp_ht_search(sock->conn_table.keys, (ecp_ecdh_public_t *)msg); + if (vconn->next) { + ecp_conn_refcount_inc(vconn->next); + } else { + rv = ECP_ERR_NEXT; + } + } else { + rv = ECP_ERR_NEXT; + } #ifdef ECP_WITH_PTHREAD pthread_mutex_unlock(&sock->conn_table.mutex); #endif - if (vconn->next == NULL) return ECP_ERR_NEXT; + if (rv) return rv; return ECP_SIZE_ECDH_PUB; } |