[asterisk-commits] russell: branch russell/issue_13566 r166055 - /team/russell/issue_13566/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 19 15:08:56 CST 2008


Author: russell
Date: Fri Dec 19 15:08:55 2008
New Revision: 166055

URL: http://svn.digium.com/view/asterisk?view=rev&rev=166055
Log:
Fix some ref count errors, seems to work fine now

Modified:
    team/russell/issue_13566/res/res_musiconhold.c

Modified: team/russell/issue_13566/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/team/russell/issue_13566/res/res_musiconhold.c?view=diff&rev=166055&r1=166054&r2=166055
==============================================================================
--- team/russell/issue_13566/res/res_musiconhold.c (original)
+++ team/russell/issue_13566/res/res_musiconhold.c Fri Dec 19 15:08:55 2008
@@ -300,24 +300,33 @@
 
 	if (!chan->music_state && (state = ast_calloc(1, sizeof(*state)))) {
 		chan->music_state = state;
-		state->class = class;
+		state->class = (ao2_ref(class, +1), class);
 		state->save_pos = -1;
-	} else 
+	} else {
 		state = chan->music_state;
-
-	if (state) {
-		if (state->class != class) {
-			/* initialize */
-			memset(state, 0, sizeof(*state));
-			state->class = class;
-			if (ast_test_flag(state->class, MOH_RANDOMIZE) && class->total_files)
-				state->pos = ast_random() % class->total_files;
-		}
-
-		state->origwfmt = chan->writeformat;
-
-		if (option_verbose > 2)
-			ast_verbose(VERBOSE_PREFIX_3 "Started music on hold, class '%s', on %s\n", class->name, chan->name);
+	}
+
+	if (!state) {
+		return NULL;
+	}
+
+	if (state->class != class) {
+		/* (re-)initialize */
+		if (state->class) {
+			state->class = (ao2_ref(state->class, -1), NULL);
+		}
+		memset(state, 0, sizeof(*state));
+		state->class = (ao2_ref(class, +1), class);
+		if (ast_test_flag(state->class, MOH_RANDOMIZE) && class->total_files) {
+			state->pos = ast_random() % class->total_files;
+		}
+	}
+
+	state->origwfmt = chan->writeformat;
+
+	if (option_verbose > 2) {
+		ast_verbose(VERBOSE_PREFIX_3 "Started music on hold, class '%s', on %s\n", 
+				class->name, chan->name);
 	}
 	
 	return chan->music_state;
@@ -938,9 +947,11 @@
 	if ((mohclass = get_mohbyname(moh->name, 0))) {
 		if (!mohclass->delete) {
  			ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name);
+			mohclass = (ao2_ref(mohclass, -1), NULL);
 			moh = (ao2_ref(moh, -1), NULL);
 			return -1;
  		}
+		mohclass = (ao2_ref(mohclass, -1), NULL);
 	}
 
 	time(&moh->start);
@@ -982,6 +993,7 @@
 static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
 {
 	struct mohclass *mohclass = NULL;
+	int res;
 
 	/* The following is the order of preference for which class to use:
 	 * 1) The channels explicitly set musicclass, which should *only* be
@@ -1014,10 +1026,14 @@
 	ast_set_flag(chan, AST_FLAG_MOH);
 
 	if (mohclass->total_files) {
-		return ast_activate_generator(chan, &moh_file_stream, mohclass);
+		res = ast_activate_generator(chan, &moh_file_stream, mohclass);
 	} else {
-		return ast_activate_generator(chan, &mohgen, mohclass);
-	}
+		res = ast_activate_generator(chan, &mohgen, mohclass);
+	}
+
+	mohclass = (ao2_ref(mohclass, -1), NULL);
+
+	return res;
 }
 
 static void local_ast_moh_stop(struct ast_channel *chan)
@@ -1037,6 +1053,10 @@
 {
 	struct mohclass *class = obj;
 	struct mohdata *member;
+
+	if (option_debug) {
+		ast_log(LOG_DEBUG, "Destroying MOH class '%s'\n", class->name);
+	}
 
 	if (class->pid > 1) {
 		char buff[8192];




More information about the asterisk-commits mailing list