<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7414">View Change</a></p><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;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/14/7414/1</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 ad7351d..ccf6a94 100644<br>--- a/channels/chan_skinny.c<br>+++ b/channels/chan_skinny.c<br>@@ -7429,6 +7429,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>@@ -7514,11 +7519,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>@@ -7685,6 +7685,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/7414">change 7414</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/7414"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13.18 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I9af7268eba14bf76960566f891320f97b974e6dd </div>
<div style="display:none"> Gerrit-Change-Number: 7414 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>