From 7155f604c174d3126ff802a98e9032f96b747f1d Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Thu, 3 Aug 2017 14:34:40 -0500 Subject: [PATCH] Fixed overwrite of session context --- secio/secio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/secio/secio.c b/secio/secio.c index d32ddec..9a6d590 100644 --- a/secio/secio.c +++ b/secio/secio.c @@ -897,11 +897,13 @@ int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPriva } } } else { - libp2p_logger_debug("secio", "Same remote connected. Replacing SessionContext.\n"); - // clean up old session context - libp2p_session_context_free(remote_peer->sessionContext); + if (remote_peer->sessionContext != local_session) { + // clean up old session context + libp2p_logger_debug("secio", "Same remote connected. Replacing SessionContext.\n"); + libp2p_session_context_free(remote_peer->sessionContext); + remote_peer->sessionContext = local_session; + } } - remote_peer->sessionContext = local_session; remote_peer->connection_type = CONNECTION_TYPE_CONNECTED; if (new_peer) {