[svn-commits] file: branch 12 r421939 - /branches/12/res/res_pjsip_transport_websocket.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Aug 24 14:18:55 CDT 2014


Author: file
Date: Sun Aug 24 14:18:51 2014
New Revision: 421939

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=421939
Log:
res_pjsip_transport_websocket: Fix a progressive memory growth.

The packet structure used to receive messages was using the transport
pool. This meant that for each parsing the pool would grow accordingly.
Since memory can not be reclaimed without resetting it this would
cause the memory pool to grow and grow.

This change uses a specific memory pool for the packet structure and
resets it to a fresh state after the message has been received and
handled.

Modified:
    branches/12/res/res_pjsip_transport_websocket.c

Modified: branches/12/res/res_pjsip_transport_websocket.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_transport_websocket.c?view=diff&rev=421939&r1=421938&r2=421939
==============================================================================
--- branches/12/res/res_pjsip_transport_websocket.c (original)
+++ branches/12/res/res_pjsip_transport_websocket.c Sun Aug 24 14:18:51 2014
@@ -90,6 +90,10 @@
 
 	pjsip_endpt_release_pool(wstransport->transport.endpt, wstransport->transport.pool);
 
+	if (wstransport->rdata.tp_info.pool) {
+		pjsip_endpt_release_pool(wstransport->transport.endpt, wstransport->rdata.tp_info.pool);
+	}
+
 	return PJ_SUCCESS;
 }
 
@@ -161,6 +165,15 @@
 	newtransport->transport.destroy = &ws_destroy;
 
 	pjsip_transport_register(newtransport->transport.tpmgr, (pjsip_transport *)newtransport);
+
+	newtransport->rdata.tp_info.transport = &newtransport->transport;
+	newtransport->rdata.tp_info.pool = pjsip_endpt_create_pool(endpt, "rtd%p",
+		PJSIP_POOL_RDATA_LEN, PJSIP_POOL_RDATA_INC);
+	if (!newtransport->rdata.tp_info.pool) {
+		ast_log(LOG_ERROR, "Failed to allocate WebSocket rdata.\n");
+		pjsip_endpt_release_pool(endpt, pool);
+		return -1;
+	}
 
 	create_data->transport = newtransport;
 	return 0;
@@ -185,9 +198,6 @@
 	int recvd;
 	pj_str_t buf;
 
-	rdata->tp_info.pool = newtransport->transport.pool;
-	rdata->tp_info.transport = &newtransport->transport;
-
 	pj_gettimeofday(&rdata->pkt_info.timestamp);
 
 	pj_memcpy(rdata->pkt_info.packet, read_data->payload, sizeof(rdata->pkt_info.packet));
@@ -203,6 +213,8 @@
 	rdata->pkt_info.src_port = ast_sockaddr_port(ast_websocket_remote_address(session));
 
 	recvd = pjsip_tpmgr_receive_packet(rdata->tp_info.transport->tpmgr, rdata);
+
+	pj_pool_reset(rdata->tp_info.pool);
 
 	return (read_data->payload_len == recvd) ? 0 : -1;
 }




More information about the svn-commits mailing list