Changeset 5173
- Timestamp:
- Sep 9, 2015 9:24:06 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip/sip_transport.c
r5097 r5173 953 953 } 954 954 955 956 static pj_bool_t is_transport_valid(pjsip_transport *tp, pjsip_tpmgr *tpmgr, 957 const pjsip_transport_key *key, 958 int key_len) 959 { 960 return (pj_hash_get(tpmgr->table, key, key_len, NULL) == (void*)tp); 961 } 962 955 963 /* 956 964 * Add ref. … … 958 966 PJ_DEF(pj_status_t) pjsip_transport_add_ref( pjsip_transport *tp ) 959 967 { 968 pjsip_tpmgr *tpmgr; 969 pjsip_transport_key key; 970 int key_len; 971 960 972 PJ_ASSERT_RETURN(tp != NULL, PJ_EINVAL); 961 973 974 /* Cache some vars for checking transport validity later */ 975 tpmgr = tp->tpmgr; 976 key_len = sizeof(tp->key.type) + tp->addr_len; 977 pj_memcpy(&key, &tp->key, key_len); 978 962 979 if (pj_atomic_inc_and_get(tp->ref_cnt) == 1) { 963 pj_lock_acquire(tp->tpmgr->lock); 964 /* Verify again. */ 965 if (pj_atomic_get(tp->ref_cnt) == 1) { 980 pj_lock_acquire(tpmgr->lock); 981 /* Verify again. But first, make sure transport is still valid 982 * (see #1883). 983 */ 984 if (is_transport_valid(tp, tpmgr, &key, key_len) && 985 pj_atomic_get(tp->ref_cnt) == 1) 986 { 966 987 if (tp->idle_timer.id != PJ_FALSE) { 967 988 pjsip_endpt_cancel_timer(tp->tpmgr->endpt, &tp->idle_timer); … … 969 990 } 970 991 } 971 pj_lock_release(tp ->tpmgr->lock);992 pj_lock_release(tpmgr->lock); 972 993 } 973 994 … … 980 1001 PJ_DEF(pj_status_t) pjsip_transport_dec_ref( pjsip_transport *tp ) 981 1002 { 1003 pjsip_tpmgr *tpmgr; 1004 pjsip_transport_key key; 1005 int key_len; 1006 982 1007 PJ_ASSERT_RETURN(tp != NULL, PJ_EINVAL); 983 984 1008 pj_assert(pj_atomic_get(tp->ref_cnt) > 0); 985 1009 1010 /* Cache some vars for checking transport validity later */ 1011 tpmgr = tp->tpmgr; 1012 key_len = sizeof(tp->key.type) + tp->addr_len; 1013 pj_memcpy(&key, &tp->key, key_len); 1014 986 1015 if (pj_atomic_dec_and_get(tp->ref_cnt) == 0) { 987 pj_lock_acquire(tp ->tpmgr->lock);1016 pj_lock_acquire(tpmgr->lock); 988 1017 /* Verify again. Do not register timer if the transport is 989 * being destroyed. 1018 * being destroyed. But first, make sure transport is still valid 1019 * (see #1883). 990 1020 */ 991 if (pj_atomic_get(tp->ref_cnt) == 0 && !tp->is_destroying) { 1021 if (is_transport_valid(tp, tpmgr, &key, key_len) && 1022 !tp->is_destroying && pj_atomic_get(tp->ref_cnt) == 0) 1023 { 992 1024 pj_time_val delay; 993 1025 … … 1010 1042 &delay); 1011 1043 } 1012 pj_lock_release(tp ->tpmgr->lock);1044 pj_lock_release(tpmgr->lock); 1013 1045 } 1014 1046 … … 1078 1110 void *entry; 1079 1111 1112 tp->is_destroying = PJ_TRUE; 1113 1080 1114 TRACE_((THIS_FILE, "Transport %s is being destroyed", tp->obj_name)); 1081 1115 1082 1116 pj_lock_acquire(tp->lock); 1083 1117 pj_lock_acquire(mgr->lock); 1084 1085 tp->is_destroying = PJ_TRUE;1086 1118 1087 1119 /*
Note: See TracChangeset
for help on using the changeset viewer.