<p>When suspending while already in t_continue when processing a reply / suspending twice in a reply.</p>
<p>Thanks to <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/giavac/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/giavac">@giavac</a>  <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="872943971" data-permission-text="Title is private" data-url="https://github.com/kamailio/kamailio/issues/2721" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/2721/hovercard" href="https://github.com/kamailio/kamailio/pull/2721">#2721</a> we can now suspend more then once in a reply route.</p>
<p>This is working well, however a memory leak was detected.</p>
<p>This modification is proposing a solution that will prevent calling <code>sip_msg_cloner</code> over an already twice over the same pointer, creating the memory leak.</p>


<h4>Pre-Submission Checklist</h4>



<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Commit message has the format required by CONTRIBUTING guide</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Commits are split per component (core, individual modules, libs, utils, ...)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Each component has a single commit (if not, squash them into one commit)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> No commits to README files for modules (changes must be done to docbook files<br>
in <code>doc/</code> subfolder, the README file is autogenerated)</li>
</ul>
<h4>Type Of Change</h4>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Small bug fix (non-breaking change which fixes an issue)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> New feature (non-breaking change which adds new functionality)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Breaking change (fix or feature that would change existing functionality)</li>
</ul>
<p>I assume this is a non "breaking change" since it can only trigger in a very the specific case that was not supported anyway.<br>
Conditions when this alternate behavior can trigger:<br>
1- must be in t_suspend<br>
2- must be in a reply <code>if (msg->first_line.type == SIP_REPLY) {</code><br>
3- must have an already cloned <code>if (t->uac[branch].reply) {</code></p>
<p>An alternate solution would be to free everything in the cloned message and recreate it.</p>
<h4>Checklist:</h4>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> PR should be backported to stable branches</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Tested changes locally</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Related to issue #XXXX (replace XXXX with an open issue number)</li>
</ul>
<p>load test done that included connections, failures and timeouts while suspending multiple times.</p>
<div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content=" 6(31) INFO: tm [t_suspend.c:126]: t_suspend(): [>>>SUSPEND<<<] cloning message !
53(78) INFO: tm [t_suspend.c:136]: t_suspend(): [>>>SUSPEND<<<] message already cloned, re-using ! 
"><pre><code> 6(31) INFO: tm [t_suspend.c:126]: t_suspend(): [>>>SUSPEND<<<] cloning message !
53(78) INFO: tm [t_suspend.c:136]: t_suspend(): [>>>SUSPEND<<<] message already cloned, re-using ! 
</code></pre></div>
<div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="Total 100000 INVITE calls sent in 1710825 ms at rate of 58/sec
Total 100000 connection responses received in 1714999 ms at rate of 58/sec:
>> Detailed connection responses received:
 - 200 connection responses:    24924     (OK)
 - 404 connection responses:    25145     (Not Found)
 - 408 connection responses:    24912     (Request Timeout)
 - 500 connection responses:    25019     (Internal Server Error)
>> Detailed disconnection responses received:
 - 200 disconnection responses:    24924     (OK)
                    ------
 TOTAL responses:    24924 (rate=14/sec)
"><pre><code>Total 100000 INVITE calls sent in 1710825 ms at rate of 58/sec
Total 100000 connection responses received in 1714999 ms at rate of 58/sec:
>> Detailed connection responses received:
 - 200 connection responses:    24924     (OK)
 - 404 connection responses:    25145     (Not Found)
 - 408 connection responses:    24912     (Request Timeout)
 - 500 connection responses:    25019     (Internal Server Error)
>> Detailed disconnection responses received:
 - 200 disconnection responses:    24924     (OK)
                    ------
 TOTAL responses:    24924 (rate=14/sec)
</code></pre></div>
<h4>Description</h4>


<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/kamailio/kamailio/pull/2763'>https://github.com/kamailio/kamailio/pull/2763</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>tm: prevent t_suspend memory leak</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/kamailio/kamailio/pull/2763/files#diff-f40adc0efd836210c2f3e832bc8b5eb609cff397720ee64c603d43fd1450d481">src/modules/tm/t_suspend.c</a>
    (21)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/kamailio/kamailio/pull/2763.patch'>https://github.com/kamailio/kamailio/pull/2763.patch</a></li>
  <li><a href='https://github.com/kamailio/kamailio/pull/2763.diff'>https://github.com/kamailio/kamailio/pull/2763.diff</a></li>
</ul>

<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/pull/2763">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZNPNG2S3MSF7FK4WL3TRFHUZANCNFSM46DUNMEA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZNHSCIZLRTW7JV3L2LTRFHUZA5CNFSM46DUNMEKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4NS2VKKQ.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/pull/2763",
"url": "https://github.com/kamailio/kamailio/pull/2763",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>