]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_transport_websocket: Fix a progressive memory growth.
authorJoshua Colp <jcolp@digium.com>
Sun, 24 Aug 2014 19:18:51 +0000 (19:18 +0000)
committerJoshua Colp <jcolp@digium.com>
Sun, 24 Aug 2014 19:18:51 +0000 (19:18 +0000)
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.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@421939 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_pjsip_transport_websocket.c

index 5bf63be2a2d8f8090848e7bf8103a12a24eac874..81326edc85a8e0bcb4ab58f29a1aff630abd559d 100644 (file)
@@ -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;
 }