[asterisk-dev] pjsip and ast_sip_add_header - memory management?

Joshua C. Colp jcolp at digium.com
Sat Aug 31 05:33:32 CDT 2019


On Sat, Aug 31, 2019, at 7:04 AM, Michael Maier wrote:
> Hello!
> 
> If there are headers added to a request using ast_sip_add_header: who 
> is responsible for the memory management of the added headers? At the 
> moment I suspect, that there is
> a memory leak using ast_sip_add_header because I can see slightly but 
> constantly more growing memory usage (see mediasec patches [1] e.g.), 
> which I didn't saw before
> (asterisk doesn't that heavily rely on ast_sip_add_header - but 
> REGISTER and OPTIONS requests are sent regularly and very often).

PJSIP itself is technically. It uses a pool approach where many structures allocate a pool and then the contents of the structure are allocated from that pool, so you can't actually free individual aspects without freeing everything about the structure by freeing the pool. This is what happens for ast_sip_add_header - it's allocated from the pool for the outgoing message, just like other parts of the message itself.

Is ast_sip_add_header being called multiple times for the same tdata? That could cause the memory usage to increase, since the pool would just grow.

-- 
Joshua C. Colp
Digium - A Sangoma Company | Senior Software Developer
445 Jan Davis Drive NW - Huntsville, AL 35806 - US
Check us out at: www.digium.com & www.asterisk.org



More information about the asterisk-dev mailing list