Changeset 5459 for pjproject/trunk/pjlib/src/pj/ssl_sock_ossl.c
- Timestamp:
- Oct 13, 2016 9:02:50 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/ssl_sock_ossl.c
r5367 r5459 823 823 asock = ssock->asock; 824 824 if (asock) { 825 ssock->asock = NULL; 825 // Don't set ssock->asock to NULL, as it may trigger assertion in 826 // send operation. This should be safe as active socket will simply 827 // return PJ_EINVALIDOP on any operation if it is already closed. 828 //ssock->asock = NULL; 826 829 ssock->sock = PJ_INVALID_SOCKET; 827 830 } … … 842 845 static void reset_ssl_sock_state(pj_ssl_sock_t *ssock) 843 846 { 847 pj_lock_acquire(ssock->write_mutex); 844 848 ssock->ssl_state = SSL_STATE_NULL; 845 846 destroy_ssl(ssock); 849 pj_lock_release(ssock->write_mutex); 847 850 848 851 close_sockets(ssock); … … 1613 1616 } 1614 1617 1618 static void ssl_on_destroy(void *arg) 1619 { 1620 pj_pool_t *pool = NULL; 1621 pj_ssl_sock_t *ssock = (pj_ssl_sock_t*)arg; 1622 1623 destroy_ssl(ssock); 1624 1625 pj_lock_destroy(ssock->write_mutex); 1626 1627 pool = ssock->pool; 1628 ssock->pool = NULL; 1629 if (pool) 1630 pj_pool_release(pool); 1631 } 1632 1615 1633 1616 1634 /* … … 1831 1849 /* Create new SSL socket instance */ 1832 1850 status = pj_ssl_sock_create(ssock_parent->pool, 1833 1851 &ssock_parent->newsock_param, &ssock); 1834 1852 if (status != PJ_SUCCESS) 1835 1853 goto on_return; … … 1907 1925 goto on_return; 1908 1926 1909 /* Temporarily add ref the group lock until active socket creation,1910 * to make sure that group lock is destroyed if the active socket1911 * creation fails.1912 */1913 1927 pj_grp_lock_add_ref(glock); 1914 1928 asock_cfg.grp_lock = ssock->param.grp_lock = glock; 1929 pj_grp_lock_add_handler(ssock->param.grp_lock, ssock->pool, ssock, 1930 ssl_on_destroy); 1915 1931 } 1916 1932 … … 1927 1943 ssock, 1928 1944 &ssock->asock); 1929 1930 /* This will destroy the group lock if active socket creation fails */1931 if (asock_cfg.grp_lock) {1932 pj_grp_lock_dec_ref(asock_cfg.grp_lock);1933 }1934 1945 1935 1946 if (status != PJ_SUCCESS) … … 2252 2263 status = pj_lock_create_recursive_mutex(pool, pool->obj_name, 2253 2264 &ssock->write_mutex); 2254 if (status != PJ_SUCCESS) 2265 if (status != PJ_SUCCESS) { 2266 pj_pool_release(pool); 2255 2267 return status; 2268 } 2256 2269 2257 2270 /* Init secure socket param */ 2258 2271 pj_ssl_sock_param_copy(pool, &ssock->param, param); 2272 2273 if (ssock->param.grp_lock) { 2274 pj_grp_lock_add_ref(ssock->param.grp_lock); 2275 pj_grp_lock_add_handler(ssock->param.grp_lock, pool, ssock, 2276 ssl_on_destroy); 2277 } 2278 2259 2279 ssock->param.read_buffer_size = ((ssock->param.read_buffer_size+7)>>3)<<3; 2260 2280 if (!ssock->param.timer_heap) { 2261 2281 PJ_LOG(3,(ssock->pool->obj_name, "Warning: timer heap is not " 2262 2282 "available. It is recommended to supply one to avoid " 2263 2264 2283 "a race condition if more than one worker threads " 2284 "are used.")); 2265 2285 } 2266 2286 … … 2278 2298 PJ_DEF(pj_status_t) pj_ssl_sock_close(pj_ssl_sock_t *ssock) 2279 2299 { 2280 pj_pool_t *pool;2281 2282 2300 PJ_ASSERT_RETURN(ssock, PJ_EINVAL); 2283 2301 … … 2291 2309 2292 2310 reset_ssl_sock_state(ssock); 2293 pj_lock_destroy(ssock->write_mutex); 2294 2295 pool = ssock->pool; 2296 ssock->pool = NULL; 2297 if (pool) 2298 pj_pool_release(pool); 2311 if (ssock->param.grp_lock) { 2312 pj_grp_lock_dec_ref(ssock->param.grp_lock); 2313 } else { 2314 ssl_on_destroy(ssock); 2315 } 2299 2316 2300 2317 return PJ_SUCCESS; … … 2783 2800 /* Start accepting */ 2784 2801 pj_ssl_sock_param_copy(pool, &ssock->newsock_param, newsock_param); 2802 ssock->newsock_param.grp_lock = NULL; 2785 2803 status = pj_activesock_start_accept(ssock->asock, pool); 2786 2804 if (status != PJ_SUCCESS)
Note: See TracChangeset
for help on using the changeset viewer.