<p>Hi <a class="user-mention" data-hovercard-user-id="29600456" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/christoph-v">@christoph-v</a><br>
Good fix...i see it's revealing another two potential issues on remove_impucontact_from_list same file (impurecord.c);  1) tail->next is not nullified on removing last impucontact--hence second last will still point to the "just-removed"  impucontact<br>
2) contact removal in mid list seems to have swapped fields on both sides of equal sign<br>
Please see below possible fix:</p>
<p>int remove_impucontact_from_list(impurecord_t* impu, impu_contact_t <em>impucontact) {<br>
ucontact_t</em> contact = impucontact->contact;</p>
<pre><code>    if (/*contact - removed*/ impucontact == impu->linked_contacts.head /*->contact - removed */) {
            LM_DBG("deleting head\n");
            impu->linked_contacts.head = impu->linked_contacts.head->next;              
    } else if (/*contact*/ impucontact== impu->linked_contacts.tail/*->contact*/) {     
            LM_DBG("deleting tail prev %p next %p\n",impu->linked_contacts.tail->prev, impu->linked_contacts.tail->next);
            impu->linked_contacts.tail = impu->linked_contacts.tail->prev;              
            impu->linked_contacts.tail->next = 0; /* Nullified end of list*/
    } else {                                                                            
            LM_DBG("deleting mid list prev %p next %p\n", impucontact->prev, impucontact->next);
            impucontact->prev->next = impucontact->next;
            /*impucontact->prev = impucontact->next->prev; removed ---- seems to be small swap-around error*/                      
            impucontact->next->prev = impucontact->prev;  /* Added */
    }                                                                                           
    impu->linked_contacts.numcontacts--;                                                
    if (impucontact->contact->is_3gpp)
            impu->linked_contacts.num3gppcontacts--;
    LM_DBG("REMOVED impu_contact %p for contact %p\n",impucontact, contact);            
    shm_free(impucontact);                                                                      
    return 0;                                                                           
</code></pre>
<p>}</p>

<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/1547#issuecomment-395767031">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZWL-e6ObY1Dy_o9u3IZ7AXdRIGgHks5t6oF5gaJpZM4UOeq1">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZeZhe0JzrrZtyhf4bb2n6aKTpd7vks5t6oF5gaJpZM4UOeq1.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/1547#issuecomment-395767031","url":"https://github.com/kamailio/kamailio/pull/1547#issuecomment-395767031","name":"View Pull Request"},"description":"View this Pull Request on GitHub","publisher":{"@type":"Organization","name":"GitHub","url":"https://github.com"}}</script>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@thulasizwe-n in #1547: Hi @christoph-v\r\nGood fix...i see it's revealing another two potential issues on remove_impucontact_from_list same file (impurecord.c);  1) tail-\u003enext is not nullified on removing last impucontact--hence second last will still point to the \"just-removed\"  impucontact\r\n                         2) contact removal in mid list seems to have swapped fields on both sides of equal sign\r\nPlease see below possible fix:\r\n\r\nint remove_impucontact_from_list(impurecord_t* impu, impu_contact_t *impucontact) {         \r\n        ucontact_t* contact = impucontact-\u003econtact;                                         \r\n                \r\n        if (/*contact - removed*/ impucontact == impu-\u003elinked_contacts.head /*-\u003econtact - removed */) {\r\n                LM_DBG(\"deleting head\\n\");\r\n                impu-\u003elinked_contacts.head = impu-\u003elinked_contacts.head-\u003enext;              \r\n        } else if (/*contact*/ impucontact== impu-\u003elinked_contacts.tail/*-\u003econtact*/) {     \r\n                LM_DBG(\"deleting tail prev %p next %p\\n\",impu-\u003elinked_contacts.tail-\u003eprev, impu-\u003elinked_contacts.tail-\u003enext);\r\n                impu-\u003elinked_contacts.tail = impu-\u003elinked_contacts.tail-\u003eprev;              \r\n                impu-\u003elinked_contacts.tail-\u003enext = 0; /* Nullified end of list*/\r\n        } else {                                                                            \r\n                LM_DBG(\"deleting mid list prev %p next %p\\n\", impucontact-\u003eprev, impucontact-\u003enext);\r\n                impucontact-\u003eprev-\u003enext = impucontact-\u003enext;\r\n                /*impucontact-\u003eprev = impucontact-\u003enext-\u003eprev; removed ---- seems to be small swap-around error*/                      \r\n                impucontact-\u003enext-\u003eprev = impucontact-\u003eprev;  /* Added */\r\n        }                                                                                           \r\n        impu-\u003elinked_contacts.numcontacts--;                                                \r\n        if (impucontact-\u003econtact-\u003eis_3gpp)\r\n                impu-\u003elinked_contacts.num3gppcontacts--;\r\n        LM_DBG(\"REMOVED impu_contact %p for contact %p\\n\",impucontact, contact);            \r\n        shm_free(impucontact);                                                                      \r\n        return 0;                                                                           \r\n}                                           \r\n"}],"action":{"name":"View Pull Request","url":"https://github.com/kamailio/kamailio/pull/1547#issuecomment-395767031"}}}</script>
<script type="application/ld+json">{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [kamailio/kamailio] ims_usrloc_scscf: bugfix Contct is removed when old Contct expires (#1547)",
"sections": [
{
"text": "",
"activityTitle": "**thulasizwe-n**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@thulasizwe-n",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1547,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/pull/1547#issuecomment-395767031"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 339339957\n}"
}
],
"themeColor": "26292E"
}</script>