[svn-commits] russell: branch 1.8 r410043 - /branches/1.8/res/res_musiconhold.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Mar 6 17:01:33 CST 2014


Author: russell
Date: Thu Mar  6 17:01:26 2014
New Revision: 410043

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=410043
Log:
moh: fix a refcount error with realtime MOH

I observed a crash in res_musiconhold on an Asterisk 11 system using realtime
MOH.  Investigation of the backtrace showed a corrupt mohclass, implying that
it got destroyed before the code expected it to.  I went looking for reference
counting errors that could have caused this crash and this patch this result.
It contains 2 changes.

1) Remove a usless block of code that was impossible to reach.  There was even
a comment indicating that it was impossible to reach.  The conditional includes
"!ast_test_flag(global_flags, MOH_CACHERTCLASSES)" and it's inside of an if
block with the opposite check "ast_test_flag(global_flags,
MOH_CACHERTCLASSES)".  There's no good reason to keep it around.

2) A similar block to #1 contained a reference counting error.  It stores
state->class in the local variable mohclass without increasing its reference
count.  The reference count on mohclass is decremented at the end of the
function.  This block of code probably very rarely runs, which would help
explain why this system was working fine for many months before experiencing a
crash.

Review: https://reviewboard.asterisk.org/r/3282/

Modified:
    branches/1.8/res/res_musiconhold.c

Modified: branches/1.8/res/res_musiconhold.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/res/res_musiconhold.c?view=diff&rev=410043&r1=410042&r2=410043
==============================================================================
--- branches/1.8/res/res_musiconhold.c (original)
+++ branches/1.8/res/res_musiconhold.c Thu Mar  6 17:01:26 2014
@@ -1431,12 +1431,6 @@
 				if (state && state->class) {
 					/* Class already exist for this channel */
 					ast_log(LOG_NOTICE, "This channel already has a MOH class attached (%s)!\n", state->class->name);
-					if (state->class->realtime && !ast_test_flag(global_flags, MOH_CACHERTCLASSES) && !strcasecmp(mohclass->name, state->class->name)) {
-						/* we found RT class with the same name, seems like we should continue playing existing one */
-						/* XXX This code is impossible to reach */
-						mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (channel already has a class)");
-						mohclass = state->class;
-					}
 				}
 				/* We don't want moh_register to unref the mohclass because we do it at the end of this function as well.
 				 * If we allowed moh_register to unref the mohclass,too, then the count would be off by one. The result would
@@ -1489,7 +1483,7 @@
 						if (state->class->realtime && !ast_test_flag(global_flags, MOH_CACHERTCLASSES) && !strcasecmp(mohclass->name, state->class->name)) {
 							/* we found RT class with the same name, seems like we should continue playing existing one */
 							mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (channel already has one)");
-							mohclass = state->class;
+							mohclass = mohclass_ref(state->class, "using existing class from state");
 						}
 					} else {
 						if (ast_pthread_create_background(&mohclass->thread, NULL, monmp3thread, mohclass)) {




More information about the svn-commits mailing list