<h3>Description</h3>
<p>We noticed one of our kamailio instances using increasing amounts of pkg memory.</p>
<p>This appears to be related to the sanity-check module.<br>
sanity.c:655 - <code>if (msg->proxy_require->parsed == NULL)</code> then that header is parsed into <code>msg->proxy_require->parsed</code>. This buffer should be free'd in sanity.c:712, but this only happens if the sanity check is succesfull. If the sanity check fails (on line 701), then the buffer is never free'd.</p>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>We can reproduce the issue by repeatedly sending the following SIP packet to kamailio.<br>
Please note that this 'Proxy-Require' header is invalid in our setup, and is most likely originally caused by an invalid configured phone.</p>
<pre><code>SUBSCRIBE sip:phone_0@example.com:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.102:5062;branch=z9hG4bK2104306013
From: "xxx" <sip:phone_0@example.com>;tag=108111795
To: "xxx" <sip:phone_0@example.com>
Call-ID: 3276145660@192.168.1.102
CSeq: 1 SUBSCRIBE
Contact: <sip:phone_0@192.168.1.102:5062>
Accept: application/x-as-feature-event+xml
Max-Forwards: 70
User-Agent: Yealink SIP-T48G 35.72.188.7
Proxy-Require: sip.example.com
Expires: 3630
Event: as-feature-event
Content-Length: 0
</code></pre>
<h3>Possible Solutions</h3>
<p>The code to free the buffer could be duplicated before the return on sanity.c:701.</p>
<p>However, it's not clear to me why the <code>msg->proxy_require->parsed</code> structure doesn't get properly free'd when msg is free'd, as most other fields in this struct seem to be destructed correctly.</p>
<p>For now, we disabled the proxy require check with:</p>
<pre><code>modparam("sanity", "default_checks", 2535)
</code></pre>
<p>this mitigates the memory leak.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.2.2 (x86_64/linux)
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 5.3.1
</code></pre>
<p>Problem still present in current master.</p>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<p>Ubuntu 16.04</p>
<pre><code>Linux tijscmp01 4.4.0-145-generic #171-Ubuntu SMP Tue Mar 26 12:43:40 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
</code></pre>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1990?email_source=notifications&email_token=ABO7UZMTZFVJJJK7ZJWZSPTP3U5XXA5CNFSM4H2UYZS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G3BNKWQ">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZOSG543T35KOGQHJ3LP3U5XXANCNFSM4H2UYZSQ">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABO7UZPVR2VOIIRABP2QUX3P3U5XXA5CNFSM4H2UYZS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G3BNKWQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1990?email_source=notifications\u0026email_token=ABO7UZMTZFVJJJK7ZJWZSPTP3U5XXA5CNFSM4H2UYZS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G3BNKWQ",
"url": "https://github.com/kamailio/kamailio/issues/1990?email_source=notifications\u0026email_token=ABO7UZMTZFVJJJK7ZJWZSPTP3U5XXA5CNFSM4H2UYZS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G3BNKWQ",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>