<p></p>
<h3>Description</h3>
<p>We noticed a PKG memory leak when using DMQ module's function <em>dmq_bcast_message</em> .</p>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>Issue can be reproduced with configuration below.</p>
<ul>
<li>3 Kamailio nodes each one listening on dedicated port 5070 for DMQ on their private IP address.</li>
<li>A dns name <em>[KAMAILIO_DNS]</em> resolving these 3 nodes:</li>
</ul>
<pre><code># dig +short A [KAMAILIO_DNS]
10.234.97.169
10.234.97.170
10.234.92.126
</code></pre>
<p>DMQ module configured as below (example for node 1)</p>
<pre><code>loadmodule "dmq.so"
...
modparam("dmq", "server_address", "sip:10.234.97.169:5070")
modparam("dmq", "notification_address", "sip:[KAMAILIO_DNS]:5070")
modparam("dmq", "ping_interval", 10)
modparam("dmq", "multi_notify", 1)
</code></pre>
<p>Each time an INVITE comes in, we use function below to broadcast custom message to all of the nodes:</p>
<pre><code>...
if(is_method("INVITE")) {
    dmq_bcast_message("invitenotification", "invite received", "text/plain");
}
...
</code></pre>
<p>This custom message is handled as below:</p>
<pre><code>request_route {
...
    if(is_method("KDMQ")) {
        if($Rp == 5070) route(DMQHANDLE);
        else drop;
    }
...
}
...

route[DMQHANDLE] {
    if($tU == "invitenotification") {
        # Doing some additional stuff here, but not the cause of the leak
        send_reply("200", "OK");
    } else {
        dmq_handle_message();
    }
}
</code></pre>
<p>Using <strong>sipp</strong> to send lots of messages, we can easily notice the free PKG memory decreasing over time (using <code>kamcmd pkg.stats</code>)</p>
<h4>Debugging Data</h4>
<p>Processes impacted by the leak are the ones processing SIP messages. In case of TCP, it is one of the tcp receivers.<br>
When doing a dump of such processes with command below:</p>
<pre><code>kamcmd cfg.set_now_int core mem_dump_pkg [PID]
</code></pre>
<p>Results are full of records like these ones:</p>
<pre><code>ALERT: qm_status:           alloc'd from core: core/parser/parse_from.c: parse_from_header(63)
ALERT: qm_status:           alloc'd from core: core/parser/parse_addr_spec.c: parse_to_param(285)
</code></pre>
<p>We are sure that the leak is generated by this DMQ broadcast function: we isolated it and noticed no leaks when removing it from a basic script configuration.</p>
<p>We tried different configurations:</p>
<ul>
<li>disabling multi_notify => memory leak still present</li>
<li>using an IP address instead of the DNS name => memory leak still present</li>
</ul>
<p>Valgrind did not help us to find out more precisely where the issue in the code could be located.</p>
<h3>Possible Solutions</h3>
<p>Would a <em>free</em> of <em>msg->from->parsed</em> be missing somewhere in DMQ code?<br>
Behavior looks very similar to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="55876144" data-permission-text="Title is private" data-url="https://github.com/kamailio/kamailio/issues/59" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/59/hovercard" href="https://github.com/kamailio/kamailio/pull/59">#59</a></p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.3.7 (x86_64/linux) c16b3f-dirty
flags: , EXTRA_DEBUGUSE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, TIMER_DEBUG, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<pre><code>Debian 9.13 under docker
Linux 4.9.0-9-amd64
</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/2600">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZOMRM53I7FTXEKJIQTSZMXDNANCNFSM4V536WQA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZMJ5XOELJI5PILA7ITSZMXDNA5CNFSM4V536WQKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4LVUCHTQ.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/2600",
"url": "https://github.com/kamailio/kamailio/issues/2600",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>