From 46503d9fb9fffedd484874d9eb842678363a8dd4 Mon Sep 17 00:00:00 2001 From: Riza Sulistyo Date: Thu, 19 Mar 2015 05:07:01 +0000 Subject: Misc (re #1782): Check if the transport being shutdown in on_accept_complete and on_connect_complete callback git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5000 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsip/sip_transport_tcp.c | 14 +++++++++++--- pjsip/src/pjsip/sip_transport_tls.c | 7 ++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pjsip/src/pjsip/sip_transport_tcp.c b/pjsip/src/pjsip/sip_transport_tcp.c index 1b55cdb0..3402eb01 100644 --- a/pjsip/src/pjsip/sip_transport_tcp.c +++ b/pjsip/src/pjsip/sip_transport_tcp.c @@ -1095,6 +1095,9 @@ static pj_bool_t on_accept_complete(pj_activesock_t *asock, PJ_ASSERT_RETURN(sock != PJ_INVALID_SOCKET, PJ_TRUE); + if (!listener->is_registered) + return PJ_FALSE; + PJ_LOG(4,(listener->factory.obj_name, "TCP listener %.*s:%d: got incoming TCP connection " "from %s, sock=%d", @@ -1133,6 +1136,9 @@ static pj_bool_t on_accept_complete(pj_activesock_t *asock, PJ_LOG(3,(tcp->base.obj_name, "New transport cancelled")); tcp_destroy(&tcp->base, status); } else { + if (tcp->base.is_shutdown || tcp->base.is_destroying) { + return PJ_TRUE; + } /* Start keep-alive timer */ if (PJSIP_TCP_KEEP_ALIVE_INTERVAL) { pj_time_val delay = {PJSIP_TCP_KEEP_ALIVE_INTERVAL, 0}; @@ -1142,12 +1148,11 @@ static pj_bool_t on_accept_complete(pj_activesock_t *asock, tcp->ka_timer.id = PJ_TRUE; pj_gettimeofday(&tcp->last_activity); } - /* Notify application of transport state accepted */ state_cb = pjsip_tpmgr_get_state_cb(tcp->base.tpmgr); if (state_cb) { pjsip_transport_state_info state_info; - + pj_bzero(&state_info, sizeof(state_info)); (*state_cb)(&tcp->base, PJSIP_TP_STATE_CONNECTED, &state_info); } @@ -1422,6 +1427,9 @@ static pj_bool_t on_connect_complete(pj_activesock_t *asock, /* Mark that pending connect() operation has completed. */ tcp->has_pending_connect = PJ_FALSE; + if (tcp->base.is_shutdown || tcp->base.is_destroying) + return PJ_FALSE; + /* Check connect() status */ if (status != PJ_SUCCESS) { @@ -1482,7 +1490,7 @@ static pj_bool_t on_connect_complete(pj_activesock_t *asock, state_cb = pjsip_tpmgr_get_state_cb(tcp->base.tpmgr); if (state_cb) { pjsip_transport_state_info state_info; - + pj_bzero(&state_info, sizeof(state_info)); (*state_cb)(&tcp->base, PJSIP_TP_STATE_CONNECTED, &state_info); } diff --git a/pjsip/src/pjsip/sip_transport_tls.c b/pjsip/src/pjsip/sip_transport_tls.c index 9230df79..7c3c7e5f 100644 --- a/pjsip/src/pjsip/sip_transport_tls.c +++ b/pjsip/src/pjsip/sip_transport_tls.c @@ -1179,6 +1179,9 @@ static pj_bool_t on_accept_complete(pj_ssl_sock_t *ssock, PJ_ASSERT_RETURN(new_ssock, PJ_TRUE); + if (!listener->is_registered) + return PJ_FALSE; + PJ_LOG(4,(listener->factory.obj_name, "TLS listener %.*s:%d: got incoming TLS connection " "from %s, sock=%d", @@ -1236,7 +1239,6 @@ static pj_bool_t on_accept_complete(pj_ssl_sock_t *ssock, tls->close_reason = PJSIP_TLS_ECERTVERIF; pjsip_transport_shutdown(&tls->base); } - /* Notify transport state to application */ state_cb = pjsip_tpmgr_get_state_cb(tls->base.tpmgr); if (state_cb) { @@ -1555,6 +1557,9 @@ static pj_bool_t on_connect_complete(pj_ssl_sock_t *ssock, tls = (struct tls_transport*) pj_ssl_sock_get_user_data(ssock); + if (tls->base.is_shutdown || tls->base.is_destroying) + return PJ_FALSE; + /* Check connect() status */ if (status != PJ_SUCCESS) { -- cgit v1.2.3