<p>I  cherry-picked it to 4.2.7 <br>
Dialog was  deleted a after 5mins (according to tdlg->end_ts
May be unref dialog after DLG_EVENT_RPL3xx  at once? I can't dive into dialog module source code now, so not sure is this safe, but it works:<br>
diff --git a/modules/dialog/dlg_hash.c b/modules/dialog/dlg_hash.c<br>
index a305468..202f0b9 100644<br>
--- a/modules/dialog/dlg_hash.c<br>
+++ b/modules/dialog/dlg_hash.c<br>
@@ -965,6 +965,7 @@ void next_state_dlg(dlg_cell_t *dlg, int event,<br>
                                case DLG_STATE_UNCONFIRMED:<br>
                                case DLG_STATE_EARLY:<br>
                                        dlg->state = DLG_STATE_DELETED;</p>

<ul>
<li>                                      unref_dlg_unsafe(dlg,1,d_entry);
                                    *unref = 1;
                                    break;
                            default:</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 or <a href="https://github.com/kamailio/kamailio/commit/23a3481302d5aca04be0e8d10f6d4ce23dbc36aa#commitcomment-16765433">view it on GitHub</a><img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZXhElG7WBDYvNCJ7-Otdwg9MZaVwks5putZugaJpZM4H0Bx2.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/commit/23a3481302d5aca04be0e8d10f6d4ce23dbc36aa#commitcomment-16765433"></link>
  <meta itemprop="name" content="View Commit"></meta>
</div>
<meta itemprop="description" content="View this Commit on GitHub"></meta>
</div>