<p><b>@miconda</b> requested changes on this pull request.</p>
<hr>
<p>In <a href="https://github.com/kamailio/kamailio/pull/2133#discussion_r352458579">src/modules/keepalive/keepalive_api.c</a>:</p>
<pre style='color:#555'>>
- LM_INFO("adding destination: %.*s\n", uri->len, uri->s);
+ LM_DBG("adding destination: %.*s\n", uri->len, uri->s);
+
+ if(ka_find_destination(uri , owner , &dest , &dest)){
+ LM_INFO("uri [%.*s] already in stack --ignoring \r\n",uri->len, uri->s);
+ dest->counter=0;
</pre>
<p>The change of the <code>dest->counter</code> is done out of the mutex zone and this operation can be done on an invalid structure if the <code>dest</code> was removed meanwhile.</p>
<hr>
<p>In <a href="https://github.com/kamailio/kamailio/pull/2133#discussion_r352460070">src/modules/keepalive/keepalive_api.c</a>:</p>
<pre style='color:#555'>> +* @abstract deletes given sip uri in allocated destination stack as named ka_alloc_destinations_list
+*
+* @param msg sip message
+* @param uri given uri
+* @param owner given owner name, not using now
+* *
+* @result 1 successful , -1 fail
+*/
+int ka_del_destination(str *uri, str *owner){
+
+ ka_dest_t *target=0,*head=0;
+
+ if(!ka_find_destination(uri,owner,&target,&head)){
+ LM_ERR("Couldnt find destination \r\n");
+ return -1;
+ }
</pre>
<p>Similar issues, <code>target</code> and <code>head</code> are retrieved from <code>ka_find_destination()</code>, followed by code out of the mutex zone and later used directly, but at that time any of them can be already deleted. So removal has to be done in the same mutex zone as it is searched.</p>
<p>Actually I do not see any good use for <code>ka_find_destination()</code> returning <code>target</code> and <code>head</code>. The function can be useful to know if the address exists, but using <code>target</code> and <code>head</code> after this function expose to segfault. Either you keep the lock set in the function at the return time and unlock later, out of the function, or just make it to return true/false on finding the destination, without returning <code>target</code> and <code>head</code>.</p>
<hr>
<p>In <a href="https://github.com/kamailio/kamailio/pull/2133#discussion_r352460409">src/modules/keepalive/keepalive_mod.c</a>:</p>
<pre style='color:#555'>>
extern struct tm_binds tmb;
int ka_ping_interval = 30;
ka_destinations_list_t *ka_destinations_list = NULL;
+str ka_ping_from = str_init("sip:keepalive@kamailio.org");
+int counter_del = 5;
</pre>
<p>I suggest adding <code>ka_</code> prefix to global variables that are not static and exposed in other files via <code>extern</code>.</p>
<hr>
<p>In <a href="https://github.com/kamailio/kamailio/pull/2133#discussion_r352460885">src/modules/keepalive/keepalive_mod.c</a>:</p>
<pre style='color:#555'>>
static cmd_export_t cmds[] = {
{"is_alive", (cmd_function)w_cmd_is_alive, 1,
fixup_spve_null, 0, ANY_ROUTE},
// internal API
+ {"add_destination", (cmd_function)w_add_destination, 2,
+ fixup_add_destination, 0, REQUEST_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE},
+ {"del_destination", (cmd_function)w_del_destination, 2,
+ fixup_add_destination, 0, ANY_ROUTE},
</pre>
<p>As more functions are exported from this module, I think is better to also prefix the exported name with <code>ka_</code>, like most modules use a common prefix for their functions. Probably we should also add an alias named <code>ka_is_alive()</code> for <code>is_alive()</code>.</p>
<hr>
<p>In <a href="https://github.com/kamailio/kamailio/pull/2133#discussion_r352461630">src/modules/keepalive/keepalive_mod.c</a>:</p>
<pre style='color:#555'>> @@ -126,6 +138,8 @@ static int mod_init(void)
*/
static void mod_destroy(void)
{
+ lock_release(ka_destinations_list->lock);
+ lock_dealloc(ka_destinations_list->lock);
}
</pre>
<p>This two have to be enclosed in <code>if(ka_destinations_list) { ... }</code>, the mod_destroy() is executed even when mod_init() is not finished, in that case ka_destinations_list is NULL, crashing kamailio at shutdown.</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/2133?email_source=notifications&email_token=ABO7UZN7ZAZZDD6RYYWFMD3QWS7W5A5CNFSM4JOEGGFKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCNQBQXY#pullrequestreview-325064799">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZJELEN646LHQEVZ7YLQWS7W5ANCNFSM4JOEGGFA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZOS6M7LA3U5MC6AYT3QWS7W5A5CNFSM4JOEGGFKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCNQBQXY.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/2133?email_source=notifications\u0026email_token=ABO7UZN7ZAZZDD6RYYWFMD3QWS7W5A5CNFSM4JOEGGFKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCNQBQXY#pullrequestreview-325064799",
"url": "https://github.com/kamailio/kamailio/pull/2133?email_source=notifications\u0026email_token=ABO7UZN7ZAZZDD6RYYWFMD3QWS7W5A5CNFSM4JOEGGFKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCNQBQXY#pullrequestreview-325064799",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>