summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2014-08-24 19:20:24 +0000
committerJoshua Colp <jcolp@digium.com>2014-08-24 19:20:24 +0000
commite86ee8e76ba0645217240abb6564fb9b0230b1df (patch)
treee42adcc645499fa8be0d84a05ed04378190feb6f
parent3592d4b39806ec581ab5995bd156fd987c759156 (diff)
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. ........ Merged revisions 421939 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@421945 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--res/res_pjsip_transport_websocket.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c
index 92e018d38..b90b6090a 100644
--- a/res/res_pjsip_transport_websocket.c
+++ b/res/res_pjsip_transport_websocket.c
@@ -90,6 +90,10 @@ static pj_status_t ws_destroy(pjsip_transport *transport)
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;
}
@@ -162,6 +166,15 @@ static int transport_create(void *data)
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 @@ static int transport_read(void *data)
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));
@@ -204,6 +214,8 @@ static int transport_read(void *data)
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;
}