<p><b>@henningw</b> commented on this pull request.</p>

<p>Thank you for the pull request! Generally all looks fine. I've had a few questions regarding the memory management in the error cases (I only looked through the code, did not tested it).</p><hr>

<p>In <a href="https://github.com/kamailio/kamailio/pull/2016#discussion_r307995353">src/modules/async/async_sleep.c</a>:</p>
<pre style='color:#555'>> +                    sizeof(struct async_ms_list));
+       if(_async_ms_list == NULL) {
+               LM_ERR("no more shm\n");
+               return -1;
+       }
+       memset(_async_ms_list, 0, sizeof(struct async_ms_list));
+       if(lock_init(&_async_ms_list->lock) == 0) {
+               LM_ERR("cannot init lock \n");
+               shm_free(_async_ms_list);
+               _async_ms_list = 0;
+               return -1;
+       }
+       return 0;
+}
+
+int async_destroy_ms_timer_list(void)
</pre>
<p>It is not necessary to shm_free the allocated _async_ms_list as well here?</p>

<hr>

<p>In <a href="https://github.com/kamailio/kamailio/pull/2016#discussion_r307995414">src/modules/async/async_sleep.c</a>:</p>
<pre style='color:#555'>> +            return -1;
+       }
+       dsize = sizeof(async_task_t) + sizeof(async_task_param_t) + sizeof(async_ms_item_t);
+
+       at = (async_task_t *)shm_malloc(dsize);
+       if(at == NULL) {
+               LM_ERR("no more shm memory\n");
+               return -1;
+       }
+       memset(at, 0, dsize);
+       at->param = (char *)at + sizeof(async_task_t);
+       atp = (async_task_param_t *)at->param;
+       ai = (async_ms_item_t *) ((char *)at +  sizeof(async_task_t) + sizeof(async_task_param_t));
+       ai->at = at;
+
+       if(cbname && cbname->len>=ASYNC_CBNAME_SIZE-1) {
</pre>
<p>Is here a shm_free for "at" missing?</p>

<hr>

<p>In <a href="https://github.com/kamailio/kamailio/pull/2016#discussion_r307995536">src/modules/async/async_sleep.c</a>:</p>
<pre style='color:#555'>> +            return -1;
+       }
+       memset(at, 0, dsize);
+       at->param = (char *)at + sizeof(async_task_t);
+       atp = (async_task_param_t *)at->param;
+       ai = (async_ms_item_t *) ((char *)at +  sizeof(async_task_t) + sizeof(async_task_param_t));
+       ai->at = at;
+
+       if(cbname && cbname->len>=ASYNC_CBNAME_SIZE-1) {
+               LM_ERR("callback name is too long: %.*s\n", cbname->len, cbname->s);
+               return -1;
+       }
+
+       t = tmb.t_gett();
+       if(t == NULL || t == T_UNDEFINED) {
+               if(tmb.t_newtran(msg) < 0) {
</pre>
<p>Same as above</p>

<hr>

<p>In <a href="https://github.com/kamailio/kamailio/pull/2016#discussion_r307995542">src/modules/async/async_sleep.c</a>:</p>
<pre style='color:#555'>> +    ai = (async_ms_item_t *) ((char *)at +  sizeof(async_task_t) + sizeof(async_task_param_t));
+       ai->at = at;
+
+       if(cbname && cbname->len>=ASYNC_CBNAME_SIZE-1) {
+               LM_ERR("callback name is too long: %.*s\n", cbname->len, cbname->s);
+               return -1;
+       }
+
+       t = tmb.t_gett();
+       if(t == NULL || t == T_UNDEFINED) {
+               if(tmb.t_newtran(msg) < 0) {
+                       LM_ERR("cannot create the transaction\n");
+                       return -1;
+               }
+               t = tmb.t_gett();
+               if(t == NULL || t == T_UNDEFINED) {
</pre>
<p>Same as above</p>

<hr>

<p>In <a href="https://github.com/kamailio/kamailio/pull/2016#discussion_r307995630">src/modules/async/async_sleep.c</a>:</p>
<pre style='color:#555'>> +    t = tmb.t_gett();
+       if(t == NULL || t == T_UNDEFINED) {
+               if(tmb.t_newtran(msg) < 0) {
+                       LM_ERR("cannot create the transaction\n");
+                       return -1;
+               }
+               t = tmb.t_gett();
+               if(t == NULL || t == T_UNDEFINED) {
+                       LM_ERR("cannot lookup the transaction\n");
+                       return -1;
+               }
+       }
+       
+       if(tmb.t_suspend(msg, &tindex, &tlabel) < 0) {
+               LM_ERR("failed to suspend the processing\n");
+               shm_free(ai);
</pre>
<p>You free here the "ai" structure - where is this memory actually allocated? And again, what about "at"?</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/2016?email_source=notifications&email_token=ABO7UZNQ2EWAUKV5RDX76STQBV2WVA5CNFSM4IHKWVP2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7Y3SIQ#pullrequestreview-267499810">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZJ4DECTVC2VL4O4DT3QBV2WVANCNFSM4IHKWVPQ">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABO7UZOOKFE2EKBUJT4ESGTQBV2WVA5CNFSM4IHKWVP2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7Y3SIQ.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/2016?email_source=notifications\u0026email_token=ABO7UZNQ2EWAUKV5RDX76STQBV2WVA5CNFSM4IHKWVP2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7Y3SIQ#pullrequestreview-267499810",
"url": "https://github.com/kamailio/kamailio/pull/2016?email_source=notifications\u0026email_token=ABO7UZNQ2EWAUKV5RDX76STQBV2WVA5CNFSM4IHKWVP2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7Y3SIQ#pullrequestreview-267499810",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>