From: George Joseph Date: Thu, 30 Nov 2017 20:38:50 +0000 (-0700) Subject: AST-2017-013: chan_skinny: Call pthread_detach when sess threads end X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6dca42879ca860033823fc6b3d2cf3b754350583;p=thirdparty%2Fasterisk.git AST-2017-013: chan_skinny: Call pthread_detach when sess threads end chan_skinny creates a new thread for each new session. In trying to be a good cleanup citizen, the threads are joinable and the unload_module function does a pthread_cancel() and a pthread_join() on any sessions that are active at that time. This has an unintended side effect though. Since you can call pthread_join on a thread that's already terminated, pthreads keeps the thread's storage around until you explicitly call pthread_join (or pthread_detach()). Since only the module_unload function was calling pthread_join, and even then only on the ones active at the tme, the storage for every thread/session ever created sticks around until asterisk exits. * A thread can detach itself so the session_destroy() function now calls pthread_detach() just before it frees the session memory allocation. The module_unload function still takes care of the ones that are still active should the module be unloaded. ASTERISK-27452 Reported by: Juan Sacco Change-Id: I9af7268eba14bf76960566f891320f97b974e6dd --- diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index 6848579258..b120c79cc8 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -7428,6 +7428,11 @@ static void destroy_session(struct skinnysession *s) } ast_mutex_unlock(&s->lock); ast_mutex_destroy(&s->lock); + + if (s->t != AST_PTHREADT_NULL) { + pthread_detach(s->t); + } + ast_free(s); } @@ -7514,11 +7519,6 @@ static void *skinny_session(void *data) int eventmessage = 0; struct pollfd fds[1]; - if (!s) { - ast_log(LOG_WARNING, "Bad Skinny Session\n"); - return 0; - } - ast_log(LOG_NOTICE, "Starting Skinny session from %s\n", ast_inet_ntoa(s->sin.sin_addr)); pthread_cleanup_push(skinny_session_cleanup, s); @@ -7684,6 +7684,7 @@ static void *accept_thread(void *ignore) s->keepalive_timeout_sched = -1; if (ast_pthread_create(&s->t, NULL, skinny_session, s)) { + s->t = AST_PTHREADT_NULL; destroy_session(s); } }