<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7417">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Jenkins2: Verified
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">AST-2017-013: chan_skinny: Call pthread_detach when sess threads end<br><br>chan_skinny creates a new thread for each new session. In trying<br>to be a good cleanup citizen, the threads are joinable and the<br>unload_module function does a pthread_cancel() and a pthread_join()<br>on any sessions that are active at that time. This has an<br>unintended side effect though. Since you can call pthread_join on a<br>thread that's already terminated, pthreads keeps the thread's<br>storage around until you explicitly call pthread_join (or<br>pthread_detach()). Since only the module_unload function was<br>calling pthread_join, and even then only on the ones active at the<br>tme, the storage for every thread/session ever created sticks<br>around until asterisk exits.<br><br>* A thread can detach itself so the session_destroy() function<br> now calls pthread_detach() just before it frees the session<br> memory allocation. The module_unload function still takes care<br> of the ones that are still active should the module be unloaded.<br><br>ASTERISK-27452<br>Reported by: Juan Sacco<br><br>Change-Id: I9af7268eba14bf76960566f891320f97b974e6dd<br>---<br>M channels/chan_skinny.c<br>1 file changed, 6 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c<br>index aeb0605..6f4231a 100644<br>--- a/channels/chan_skinny.c<br>+++ b/channels/chan_skinny.c<br>@@ -7426,6 +7426,11 @@<br> }<br> ast_mutex_unlock(&s->lock);<br> ast_mutex_destroy(&s->lock);<br>+<br>+ if (s->t != AST_PTHREADT_NULL) {<br>+ pthread_detach(s->t);<br>+ }<br>+<br> ast_free(s);<br> }<br> <br>@@ -7511,11 +7516,6 @@<br> int dlen = 0;<br> int eventmessage = 0;<br> struct pollfd fds[1];<br>-<br>- if (!s) {<br>- ast_log(LOG_WARNING, "Bad Skinny Session\n");<br>- return 0;<br>- }<br> <br> ast_log(LOG_NOTICE, "Starting Skinny session from %s\n", ast_inet_ntoa(s->sin.sin_addr));<br> <br>@@ -7682,6 +7682,7 @@<br> s->keepalive_timeout_sched = -1;<br> <br> if (ast_pthread_create(&s->t, NULL, skinny_session, s)) {<br>+ s->t = AST_PTHREADT_NULL;<br> destroy_session(s);<br> }<br> }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7417">change 7417</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7417"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15.1 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I9af7268eba14bf76960566f891320f97b974e6dd </div>
<div style="display:none"> Gerrit-Change-Number: 7417 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>