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 ........ Merged revisions 421945 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@421950 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
2c0cbf8e64
commit
477e2e6edb
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue