[asterisk-commits] rmudgett: branch 1.8 r337973 - in /branches/1.8: apps/ cdr/ cel/ funcs/ inclu...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 26 14:30:43 CDT 2011


Author: rmudgett
Date: Mon Sep 26 14:30:39 2011
New Revision: 337973

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=337973
Log:
Fix deadlock when using dummy channels.

Dummy channels created by ast_dummy_channel_alloc() should be destoyed by
ast_channel_unref().  Using ast_channel_release() needlessly grabs the
channel container lock and can cause a deadlock as a result.

* Analyzed use of ast_dummy_channel_alloc() and made use
ast_channel_unref() when done with the dummy channel.  (Primary reason for
the reported deadlock.)

* Made app_dial.c:dial_exec_full() not call ast_call() holding any channel
locks.  Chan_local could not perform deadlock avoidance correctly.
(Potential deadlock exposed by this issue.  Secondary reason for the
reported deadlock since the held lock was part of the deadlock chain.)

* Fixed some uses of ast_dummy_channel_alloc() not checking the returned
channel pointer for failure.

* Fixed some potential chan=NULL pointer usage in func_odbc.c.  Protected
by testing the bogus_chan value.

* Fixed needlessly clearing a 1024 char auto array when setting the first
char to zero is enough in manager.c:action_getvar().

(closes issue ASTERISK-18613)
Reported by: Thomas Arimont
Patches:
      jira_asterisk_18613_v1.8.patch (license #5621) patch uploaded by rmudgett
Tested by: Thomas Arimont

Modified:
    branches/1.8/apps/app_dial.c
    branches/1.8/apps/app_minivm.c
    branches/1.8/apps/app_voicemail.c
    branches/1.8/cdr/cdr_custom.c
    branches/1.8/cdr/cdr_manager.c
    branches/1.8/cdr/cdr_sqlite3_custom.c
    branches/1.8/cdr/cdr_syslog.c
    branches/1.8/cel/cel_custom.c
    branches/1.8/cel/cel_sqlite3_custom.c
    branches/1.8/funcs/func_odbc.c
    branches/1.8/include/asterisk/cel.h
    branches/1.8/include/asterisk/channel.h
    branches/1.8/main/cel.c
    branches/1.8/main/logger.c
    branches/1.8/main/manager.c
    branches/1.8/main/pbx.c
    branches/1.8/tests/test_gosub.c

Modified: branches/1.8/apps/app_dial.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_dial.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/apps/app_dial.c (original)
+++ branches/1.8/apps/app_dial.c Mon Sep 26 14:30:39 2011
@@ -2325,7 +2325,9 @@
 			ast_copy_string(tc->exten, chan->exten, sizeof(tc->exten));
 
 		ast_channel_unlock(tc);
+		ast_channel_unlock(chan);
 		res = ast_call(tc, numsubst, 0); /* Place the call, but don't wait on the answer */
+		ast_channel_lock(chan);
 
 		/* Save the info in cdr's that we called them */
 		if (chan->cdr)

Modified: branches/1.8/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_minivm.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/apps/app_minivm.c (original)
+++ branches/1.8/apps/app_minivm.c Mon Sep 26 14:30:39 2011
@@ -1313,6 +1313,9 @@
 	}
 	/* Allocate channel used for chanvar substitution */
 	ast = ast_dummy_channel_alloc();
+	if (!ast) {
+		return -1;
+	}
 
 	snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60);
 
@@ -1473,8 +1476,7 @@
 	ast_safe_system(tmp2);
 	ast_debug(1, "Sent message to %s with command '%s' - %s\n", vmu->email, global_mailcmd, template->attachment ? "(media attachment)" : "");
 	ast_debug(3, "Actual command used: %s\n", tmp2);
-	if (ast)
-		ast = ast_channel_release(ast);
+	ast = ast_channel_unref(ast);
 	ast_free(str1);
 	ast_free(str2);
 	return 0;

Modified: branches/1.8/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_voicemail.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/apps/app_voicemail.c (original)
+++ branches/1.8/apps/app_voicemail.c Mon Sep 26 14:30:39 2011
@@ -4581,7 +4581,7 @@
 			} else {
 				fprintf(p, "From: %s <%s>" ENDL, ast_str_quote(&str2, 0, ast_str_buffer(str1)), who);
 			}
-			ast = ast_channel_release(ast);
+			ast = ast_channel_unref(ast);
 		} else {
 			ast_log(AST_LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 		}
@@ -4626,7 +4626,7 @@
 			} else {
 				fprintf(p, "Subject: %s" ENDL, ast_str_buffer(str1));
 			}
-			ast = ast_channel_release(ast);
+			ast = ast_channel_unref(ast);
 		} else {
 			ast_log(AST_LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 		}
@@ -4712,7 +4712,7 @@
 #else
 			fprintf(p, "%s" ENDL, ast_str_buffer(str1));
 #endif
-			ast = ast_channel_release(ast);
+			ast = ast_channel_unref(ast);
 		} else {
 			ast_log(AST_LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 		}
@@ -4939,7 +4939,7 @@
 			} else {
 				fprintf(p, "From: %s <%s>" ENDL, ast_str_quote(&str2, 0, ast_str_buffer(str1)), who);
 			}
-			ast = ast_channel_release(ast);
+			ast = ast_channel_unref(ast);
 		} else {
 			ast_log(AST_LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 		}
@@ -4983,7 +4983,7 @@
 			} else {
 				fprintf(p, "Subject: %s" ENDL, ast_str_buffer(str1));
 			}
-			ast = ast_channel_release(ast);
+			ast = ast_channel_unref(ast);
 		} else {
 			ast_log(AST_LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 		}
@@ -5001,7 +5001,7 @@
 			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, fromfolder, cidnum, cidname, dur, date, category, flag);
 			ast_str_substitute_variables(&str1, 0, ast, pagerbody);
 			fprintf(p, "%s" ENDL, ast_str_buffer(str1));
-			ast = ast_channel_release(ast);
+			ast = ast_channel_unref(ast);
 		} else {
 			ast_log(AST_LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 		}
@@ -12699,6 +12699,9 @@
 		!(vmu = find_or_create(testcontext, testmailbox))) {
 		ast_test_status_update(test, "Cannot create vmu structure\n");
 		ast_unreplace_sigchld();
+#ifdef IMAP_STORAGE
+		chan = ast_channel_unref(chan);
+#endif
 		return AST_TEST_FAIL;
 	}
 
@@ -12718,6 +12721,9 @@
 				ast_test_status_update(test, "Unable to create test voicemail: %s\n",
 					syserr > 0 ? strerror(syserr) : "unable to fork()");
 				ast_unreplace_sigchld();
+#ifdef IMAP_STORAGE
+				chan = ast_channel_unref(chan);
+#endif
 				return AST_TEST_FAIL;
 			}
 		}
@@ -12791,7 +12797,7 @@
 	}
 
 #ifdef IMAP_STORAGE
-	chan = ast_channel_release(chan);
+	chan = ast_channel_unref(chan);
 #endif
 
 	/* And remove test directory */

Modified: branches/1.8/cdr/cdr_custom.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cdr/cdr_custom.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/cdr/cdr_custom.c (original)
+++ branches/1.8/cdr/cdr_custom.c Mon Sep 26 14:30:39 2011
@@ -129,7 +129,6 @@
 	}
 
 	dummy = ast_dummy_channel_alloc();
-
 	if (!dummy) {
 		ast_log(LOG_ERROR, "Unable to allocate channel for variable subsitution.\n");
 		return -1;
@@ -169,7 +168,7 @@
 
 	AST_RWLIST_UNLOCK(&sinks);
 
-	ast_channel_release(dummy);
+	ast_channel_unref(dummy);
 
 	return 0;
 }

Modified: branches/1.8/cdr/cdr_manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cdr/cdr_manager.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/cdr/cdr_manager.c (original)
+++ branches/1.8/cdr/cdr_manager.c Mon Sep 26 14:30:39 2011
@@ -167,7 +167,7 @@
 		}
 		dummy->cdr = ast_cdr_dup(cdr);
 		pbx_substitute_variables_helper(dummy, ast_str_buffer(customfields), buf, sizeof(buf) - 1);
-		ast_channel_release(dummy);
+		ast_channel_unref(dummy);
 	}
 	ast_rwlock_unlock(&customfields_lock);
 

Modified: branches/1.8/cdr/cdr_sqlite3_custom.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cdr/cdr_sqlite3_custom.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/cdr/cdr_sqlite3_custom.c (original)
+++ branches/1.8/cdr/cdr_sqlite3_custom.c Mon Sep 26 14:30:39 2011
@@ -261,7 +261,7 @@
 		}
 		sql = sqlite3_mprintf("INSERT INTO %q (%s) VALUES (%s)", table, columns, ast_str_buffer(value_string));
 		ast_debug(1, "About to log: %s\n", sql);
-		ast_channel_release(dummy);
+		ast_channel_unref(dummy);
 		ast_free(value_string);
 	}
 

Modified: branches/1.8/cdr/cdr_syslog.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cdr/cdr_syslog.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/cdr/cdr_syslog.c (original)
+++ branches/1.8/cdr/cdr_syslog.c Mon Sep 26 14:30:39 2011
@@ -116,7 +116,7 @@
 
 	AST_RWLIST_UNLOCK(&sinks);
 
-	ast_channel_release(dummy);
+	ast_channel_unref(dummy);
 
 	return 0;
 }

Modified: branches/1.8/cel/cel_custom.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cel/cel_custom.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/cel/cel_custom.c (original)
+++ branches/1.8/cel/cel_custom.c Mon Sep 26 14:30:39 2011
@@ -128,7 +128,6 @@
 	}
 
 	dummy = ast_cel_fabricate_channel_from_event(event);
-
 	if (!dummy) {
 		ast_log(LOG_ERROR, "Unable to fabricate channel from CEL event.\n");
 		return;
@@ -163,7 +162,7 @@
 
 	AST_RWLIST_UNLOCK(&sinks);
 
-	ast_channel_release(dummy);
+	ast_channel_unref(dummy);
 }
 
 static int unload_module(void)

Modified: branches/1.8/cel/cel_sqlite3_custom.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cel/cel_sqlite3_custom.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/cel/cel_sqlite3_custom.c (original)
+++ branches/1.8/cel/cel_sqlite3_custom.c Mon Sep 26 14:30:39 2011
@@ -262,7 +262,7 @@
 		}
 		sql = sqlite3_mprintf("INSERT INTO %q (%s) VALUES (%s)", table, columns, ast_str_buffer(value_string));
 		ast_debug(1, "About to log: %s\n", sql);
-		dummy = ast_channel_release(dummy);
+		dummy = ast_channel_unref(dummy);
 		ast_free(value_string);
 	}
 

Modified: branches/1.8/funcs/func_odbc.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_odbc.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/funcs/func_odbc.c (original)
+++ branches/1.8/funcs/func_odbc.c Mon Sep 26 14:30:39 2011
@@ -267,7 +267,7 @@
 			ast_autoservice_stop(chan);
 			pbx_builtin_setvar_helper(chan, "ODBCSTATUS", status);
 		} else {
-			ast_channel_release(chan);
+			ast_channel_unref(chan);
 		}
 		return -1;
 	}
@@ -292,7 +292,7 @@
 	ast_str_substitute_variables(&insertbuf, 0, chan, query->sql_insert);
 
 	if (bogus_chan) {
-		chan = ast_channel_release(chan);
+		chan = ast_channel_unref(chan);
 	} else {
 		/* Restore prior values */
 		for (i = 0; i < args.argc; i++) {
@@ -474,7 +474,7 @@
 	ast_str_substitute_variables(&sql, 0, chan, query->sql_read);
 
 	if (bogus_chan) {
-		chan = ast_channel_release(chan);
+		chan = ast_channel_unref(chan);
 	} else {
 		/* Restore prior values */
 		for (x = 0; x < args.argc; x++) {
@@ -596,11 +596,9 @@
 				SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 				ast_odbc_release_obj(obj);
 				obj = NULL;
-				pbx_builtin_setvar_helper(chan, "ODBCSTATUS", "MEMERROR");
-				if (chan)
+				if (!bogus_chan) {
+					pbx_builtin_setvar_helper(chan, "ODBCSTATUS", "MEMERROR");
 					ast_autoservice_stop(chan);
-				if (bogus_chan) {
-					ast_channel_release(chan);
 				}
 				return -1;
 			}
@@ -631,9 +629,11 @@
 						SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 						ast_odbc_release_obj(obj);
 						obj = NULL;
-						pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
-						pbx_builtin_setvar_helper(chan, "ODBCSTATUS", "MEMERROR");
-						ast_autoservice_stop(chan);
+						if (!bogus_chan) {
+							pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
+							pbx_builtin_setvar_helper(chan, "ODBCSTATUS", "MEMERROR");
+							ast_autoservice_stop(chan);
+						}
 						return -1;
 					}
 					resultset = tmp;
@@ -1142,6 +1142,10 @@
 	char_args = ast_strdupa(a->argv[3]);
 
 	chan = ast_dummy_channel_alloc();
+	if (!chan) {
+		AST_RWLIST_UNLOCK(&queries);
+		return CLI_FAILURE;
+	}
 
 	AST_STANDARD_APP_ARGS(args, char_args);
 	for (i = 0; i < args.argc; i++) {
@@ -1150,7 +1154,7 @@
 	}
 
 	ast_str_substitute_variables(&sql, 0, chan, query->sql_read);
-	chan = ast_channel_release(chan);
+	chan = ast_channel_unref(chan);
 
 	if (a->argc == 5 && !strcmp(a->argv[4], "exec")) {
 		/* Execute the query */
@@ -1352,6 +1356,10 @@
 	char_values = ast_strdupa(a->argv[4]);
 
 	chan = ast_dummy_channel_alloc();
+	if (!chan) {
+		AST_RWLIST_UNLOCK(&queries);
+		return CLI_FAILURE;
+	}
 
 	AST_STANDARD_APP_ARGS(args, char_args);
 	for (i = 0; i < args.argc; i++) {
@@ -1370,7 +1378,8 @@
 	pbx_builtin_pushvar_helper(chan, "VALUE", S_OR(a->argv[4], ""));
 	ast_str_substitute_variables(&sql, 0, chan, query->sql_write);
 	ast_debug(1, "SQL is %s\n", ast_str_buffer(sql));
-	chan = ast_channel_release(chan);
+
+	chan = ast_channel_unref(chan);
 
 	if (a->argc == 6 && !strcmp(a->argv[5], "exec")) {
 		/* Execute the query */

Modified: branches/1.8/include/asterisk/cel.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/cel.h?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/include/asterisk/cel.h (original)
+++ branches/1.8/include/asterisk/cel.h Mon Sep 26 14:30:39 2011
@@ -183,8 +183,11 @@
 /*!
  * \brief Create a fake channel from data in a CEL event
  *
- * This function creates a fake channel containing the serialized channel data 
- * in the given cel event.  It must be released with ast_channel_release.
+ * \note
+ * This function creates a fake channel containing the
+ * serialized channel data in the given cel event.  It should be
+ * released with ast_channel_unref() but could be released with
+ * ast_channel_release().
  *
  * \param event the CEL event
  *

Modified: branches/1.8/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/channel.h?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/include/asterisk/channel.h (original)
+++ branches/1.8/include/asterisk/channel.h Mon Sep 26 14:30:39 2011
@@ -1130,6 +1130,7 @@
 	__ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, \
 			    __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
 
+#if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
 /*!
  * \brief Create a fake channel structure
  *
@@ -1139,11 +1140,32 @@
  * \note This function should ONLY be used to create a fake channel
  *       that can then be populated with data for use in variable
  *       substitution when a real channel does not exist.
- */
-#if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
+ *
+ * \note The created dummy channel should be destroyed by
+ * ast_channel_unref().  Using ast_channel_release() needlessly
+ * grabs the channel container lock and can cause a deadlock as
+ * a result.  Also grabbing the channel container lock reduces
+ * system performance.
+ */
 #define ast_dummy_channel_alloc()	__ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
 struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function);
 #else
+/*!
+ * \brief Create a fake channel structure
+ *
+ * \retval NULL failure
+ * \retval non-NULL successfully allocated channel
+ *
+ * \note This function should ONLY be used to create a fake channel
+ *       that can then be populated with data for use in variable
+ *       substitution when a real channel does not exist.
+ *
+ * \note The created dummy channel should be destroyed by
+ * ast_channel_unref().  Using ast_channel_release() needlessly
+ * grabs the channel container lock and can cause a deadlock as
+ * a result.  Also grabbing the channel container lock reduces
+ * system performance.
+ */
 struct ast_channel *ast_dummy_channel_alloc(void);
 #endif
 
@@ -1589,6 +1611,7 @@
 
 /*!
  * \brief Make a call
+ * \note Absolutely _NO_ channel locks should be held before calling this function.
  * \param chan which channel to make the call on
  * \param addr destination of the call
  * \param timeout time to wait on for connect

Modified: branches/1.8/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/cel.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/main/cel.c (original)
+++ branches/1.8/main/cel.c Mon Sep 26 14:30:39 2011
@@ -417,7 +417,7 @@
 
 	/* first, get the variables from the event */
 	if (ast_cel_fill_record(event, &record)) {
-		ast_channel_release(tchan);
+		ast_channel_unref(tchan);
 		return NULL;
 	}
 

Modified: branches/1.8/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/logger.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/main/logger.c (original)
+++ branches/1.8/main/logger.c Mon Sep 26 14:30:39 2011
@@ -646,12 +646,15 @@
 	if (!ast_strlen_zero(exec_after_rotate)) {
 		struct ast_channel *c = ast_dummy_channel_alloc();
 		char buf[512];
+
 		pbx_builtin_setvar_helper(c, "filename", filename);
 		pbx_substitute_variables_helper(c, exec_after_rotate, buf, sizeof(buf));
+		if (c) {
+			c = ast_channel_unref(c);
+		}
 		if (ast_safe_system(buf) == -1) {
 			ast_log(LOG_WARNING, "error executing '%s'\n", buf);
 		}
-		c = ast_channel_release(c);
 	}
 	return res;
 }

Modified: branches/1.8/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/manager.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/main/manager.c (original)
+++ branches/1.8/main/manager.c Mon Sep 26 14:30:39 2011
@@ -3078,7 +3078,7 @@
 	const char *name = astman_get_header(m, "Channel");
 	const char *varname = astman_get_header(m, "Variable");
 	char *varval;
-	char workspace[1024] = "";
+	char workspace[1024];
 
 	if (ast_strlen_zero(varname)) {
 		astman_send_error(s, m, "No variable specified");
@@ -3092,12 +3092,12 @@
 		}
 	}
 
+	workspace[0] = '\0';
 	if (varname[strlen(varname) - 1] == ')') {
 		if (!c) {
 			c = ast_dummy_channel_alloc();
 			if (c) {
 				ast_func_read(c, (char *) varname, workspace, sizeof(workspace));
-				c = ast_channel_release(c);
 			} else
 				ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
 		} else {

Modified: branches/1.8/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/pbx.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/main/pbx.c (original)
+++ branches/1.8/main/pbx.c Mon Sep 26 14:30:39 2011
@@ -3721,7 +3721,7 @@
 						cp4 = ast_func_read2(c, finalvars, &substr3, 0) ? NULL : ast_str_buffer(substr3);
 						/* Don't deallocate the varshead that was passed in */
 						memcpy(&bogus->varshead, &old, sizeof(bogus->varshead));
-						ast_channel_release(bogus);
+						ast_channel_unref(bogus);
 					} else {
 						ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
 					}
@@ -3920,7 +3920,7 @@
 						cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
 						/* Don't deallocate the varshead that was passed in */
 						memcpy(&c->varshead, &old, sizeof(c->varshead));
-						c = ast_channel_release(c);
+						c = ast_channel_unref(c);
 					} else {
 						ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
 					}
@@ -8321,12 +8321,16 @@
 	/* If we are adding a hint evalulate in variables and global variables */
 	if (priority == PRIORITY_HINT && strstr(application, "${") && !strstr(extension, "_")) {
 		struct ast_channel *c = ast_dummy_channel_alloc();
-		ast_copy_string(c->exten, extension, sizeof(c->exten));
-		ast_copy_string(c->context, con->name, sizeof(c->context));
-
+
+		if (c) {
+			ast_copy_string(c->exten, extension, sizeof(c->exten));
+			ast_copy_string(c->context, con->name, sizeof(c->context));
+		}
 		pbx_substitute_variables_helper(c, application, expand_buf, sizeof(expand_buf));
 		application = expand_buf;
-		ast_channel_release(c);
+		if (c) {
+			ast_channel_unref(c);
+		}
 	}
 
 	length = sizeof(struct ast_exten);
@@ -8578,7 +8582,7 @@
 	chan->cdr = ast_cdr_alloc();
 	if (!chan->cdr) {
 		/* allocation of the cdr failed */
-		chan = ast_channel_release(chan);   /* free the channel */
+		chan = ast_channel_unref(chan);   /* free the channel */
 		return -1;                /* return failure */
 	}
 
@@ -8589,7 +8593,7 @@
 	ast_cdr_failed(chan->cdr);      /* set the status to failed */
 	ast_cdr_detach(chan->cdr);      /* post and free the record */
 	chan->cdr = NULL;
-	chan = ast_channel_release(chan);         /* free the channel */
+	chan = ast_channel_unref(chan);         /* free the channel */
 
 	return 0;  /* success */
 }

Modified: branches/1.8/tests/test_gosub.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/tests/test_gosub.c?view=diff&rev=337973&r1=337972&r2=337973
==============================================================================
--- branches/1.8/tests/test_gosub.c (original)
+++ branches/1.8/tests/test_gosub.c Mon Sep 26 14:30:39 2011
@@ -102,7 +102,7 @@
 
 	if (!(str = ast_str_create(16))) {
 		ast_test_status_update(test, "Unable to allocate dynamic string buffer\n");
-		ast_channel_release(chan);
+		ast_channel_unref(chan);
 		return AST_TEST_FAIL;
 	}
 
@@ -110,7 +110,7 @@
 	if (!(con = ast_context_find_or_create(NULL, NULL, "tests_test_gosub_virtual_context", "test_gosub"))) {
 		ast_test_status_update(test, "Unable to create test dialplan context");
 		ast_free(str);
-		ast_channel_release(chan);
+		ast_channel_unref(chan);
 		return AST_TEST_FAIL;
 	}
 
@@ -144,7 +144,7 @@
 	}
 
 	ast_free(str);
-	ast_channel_release(chan);
+	ast_channel_unref(chan);
 	ast_context_remove_extension2(con, "s", 1, NULL, 0);
 	ast_context_destroy(con, "test_gosub");
 




More information about the asterisk-commits mailing list