[asterisk-commits] mnicholson: branch group/newcdr r200002 - in /team/group/newcdr: apps/ cel/ i...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 10 15:50:02 CDT 2009


Author: mnicholson
Date: Wed Jun 10 15:49:57 2009
New Revision: 200002

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=200002
Log:
Reimplement ast_dummy_channel_alloc() using astobj2.

Modified:
    team/group/newcdr/apps/app_minivm.c
    team/group/newcdr/cel/cel_custom.c
    team/group/newcdr/cel/cel_sqlite3_custom.c
    team/group/newcdr/include/asterisk/cel.h
    team/group/newcdr/include/asterisk/channel.h
    team/group/newcdr/main/channel.c
    team/group/newcdr/main/logger.c
    team/group/newcdr/main/pbx.c

Modified: team/group/newcdr/apps/app_minivm.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/apps/app_minivm.c?view=diff&rev=200002&r1=200001&r2=200002
==============================================================================
--- team/group/newcdr/apps/app_minivm.c (original)
+++ team/group/newcdr/apps/app_minivm.c Wed Jun 10 15:49:57 2009
@@ -1461,7 +1461,7 @@
 	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_dummy_channel_free(ast);
+		ast = ast_channel_release(ast);
 	ast_free(str1);
 	ast_free(str2);
 	return 0;

Modified: team/group/newcdr/cel/cel_custom.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_custom.c?view=diff&rev=200002&r1=200001&r2=200002
==============================================================================
--- team/group/newcdr/cel/cel_custom.c (original)
+++ team/group/newcdr/cel/cel_custom.c Wed Jun 10 15:49:57 2009
@@ -132,7 +132,7 @@
 	memset(buf, 0 , sizeof(buf));
 	pbx_substitute_variables_helper(tchan, format, buf, sizeof(buf) - 1);
 
-	ast_dummy_channel_free(tchan);
+	tchan = ast_channel_release(tchan);
 
 	/* because of the absolutely unconditional need for the
 	   highest reliability possible in writing billing records,

Modified: team/group/newcdr/cel/cel_sqlite3_custom.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_sqlite3_custom.c?view=diff&rev=200002&r1=200001&r2=200002
==============================================================================
--- team/group/newcdr/cel/cel_sqlite3_custom.c (original)
+++ team/group/newcdr/cel/cel_sqlite3_custom.c Wed Jun 10 15:49:57 2009
@@ -181,7 +181,7 @@
 		do_escape(sql_cmd, sql_insert_cmd);
 	}
 
-	ast_dummy_channel_free(tchan);
+	tchan = ast_channel_release(tchan);
 
 	ast_mutex_lock(&lock);
 

Modified: team/group/newcdr/include/asterisk/cel.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/include/asterisk/cel.h?view=diff&rev=200002&r1=200001&r2=200002
==============================================================================
--- team/group/newcdr/include/asterisk/cel.h (original)
+++ team/group/newcdr/include/asterisk/cel.h Wed Jun 10 15:49:57 2009
@@ -124,7 +124,7 @@
 void ast_cel_check_retire_linkedid(const struct ast_channel *chan);
 
 /*! Create a fake channel containing the serialized channel date in
- the given cel event.  Must be freed with ast_dummy_channel_free */
+ the given cel event.  Must be released with ast_channel_release */
 struct ast_channel* ast_cel_fabricate_channel_from_event(const struct ast_event *event);
 
 /*! Frees the cel struct */

Modified: team/group/newcdr/include/asterisk/channel.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/include/asterisk/channel.h?view=diff&rev=200002&r1=200001&r2=200002
==============================================================================
--- team/group/newcdr/include/asterisk/channel.h (original)
+++ team/group/newcdr/include/asterisk/channel.h Wed Jun 10 15:49:57 2009
@@ -1046,9 +1046,6 @@
  */
 struct ast_channel *ast_channel_release(struct ast_channel *chan);
 
-/*! \brief Free a channel structure allocated with ast_dummy_channel_alloc */
-void  ast_dummy_channel_free(struct ast_channel *);
-
 /*! 
  * \brief Requests a channel
  *

Modified: team/group/newcdr/main/channel.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/channel.c?view=diff&rev=200002&r1=200001&r2=200002
==============================================================================
--- team/group/newcdr/main/channel.c (original)
+++ team/group/newcdr/main/channel.c Wed Jun 10 15:49:57 2009
@@ -779,6 +779,7 @@
 };
 
 static void ast_channel_destructor(void *obj);
+static void ast_dummy_channel_destructor(void *obj);
 
 /*! \brief Create a new channel structure */
 static struct ast_channel * attribute_malloc __attribute__((format(printf, 13, 0)))
@@ -1029,17 +1030,38 @@
  * structure that can be used to expand channel vars */
 struct ast_channel *ast_dummy_channel_alloc(void)
 {
-	struct ast_channel *chan;
+	struct ast_channel *tmp;
 	struct varshead *headp;
 
-    if (!(chan = ast_calloc(1, sizeof(*chan))))
+	/* If shutting down, don't allocate any new channels */
+	if (shutting_down) {
+		ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
 		return NULL;
-
-	ast_string_field_init(chan, 128);
-	headp = &chan->varshead;
+	}
+
+#if defined(REF_DEBUG)
+	if (!(tmp = __ao2_alloc_debug(sizeof(*tmp), ast_dummy_channel_destructor, "", file, line, function, 1))) {
+		return NULL;
+	}
+#elif defined(__AST_DEBUG_MALLOC)
+	if (!(tmp = __ao2_alloc_debug(sizeof(*tmp), ast_dummy_channel_destructor, "", file, line, function, 0))) {
+		return NULL;
+	}
+#else
+	if (!(tmp = ao2_alloc(sizeof(*tmp), ast_dummy_channel_destructor))) {
+		return NULL;
+	}
+#endif
+
+	if ((ast_string_field_init(tmp, 128))) {
+		ast_channel_unref(tmp);
+		return NULL;
+	}
+
+	headp = &tmp->varshead;
 	AST_LIST_HEAD_INIT_NOLOCK(headp);
 
-	return chan;
+	return tmp;
 }
 
 /*! \brief Queue an outgoing media frame */
@@ -1795,32 +1817,23 @@
 	ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name);
 }
 
-
-void ast_dummy_channel_free(struct ast_channel *chan)
-{
+/*! \brief Free a dummy channel structure */
+static void ast_dummy_channel_destructor(void *obj)
+{
+	struct ast_channel *chan = obj;
 	struct ast_var_t *vardata;
-	struct varshead *headp = &chan->varshead;
-
-	/* get rid of the headp list, it's function is done */
+	struct varshead *headp;
+
+	headp = &chan->varshead;
+
+	free_cid(&chan->cid);
+
+	/* loop over the variables list, freeing all data and deleting list items */
+	/* no need to lock the list, as the channel is already locked */
 	while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
 		ast_var_delete(vardata);
+
 	ast_string_field_free_memory(chan);
-	if (chan->cid.cid_name)
-		free(chan->cid.cid_name);
-	if (chan->cid.cid_num)
-		free(chan->cid.cid_num);
-	if (chan->cid.cid_ani)
-		free(chan->cid.cid_ani);
-	if (chan->cid.cid_rdnis)
-		free(chan->cid.cid_rdnis);
-	if (chan->cid.cid_dnid)
-		free(chan->cid.cid_dnid);
-	if (chan->appl)
-		free((char*)chan->appl);
-	if (chan->data)
-		free((char*)chan->data);
-
-	free(chan);
 }
 
 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)

Modified: team/group/newcdr/main/logger.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/logger.c?view=diff&rev=200002&r1=200001&r2=200002
==============================================================================
--- team/group/newcdr/main/logger.c (original)
+++ team/group/newcdr/main/logger.c Wed Jun 10 15:49:57 2009
@@ -619,7 +619,7 @@
 		if (ast_safe_system(buf) != -1) {
 			ast_log(LOG_WARNING, "error executing '%s'\n", buf);
 		}
-		ast_dummy_channel_free(c);
+		c = ast_channel_release(c);
 	}
 	return res;
 }

Modified: team/group/newcdr/main/pbx.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/pbx.c?view=diff&rev=200002&r1=200001&r2=200002
==============================================================================
--- team/group/newcdr/main/pbx.c (original)
+++ team/group/newcdr/main/pbx.c Wed Jun 10 15:49:57 2009
@@ -3832,7 +3832,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));
-						ast_dummy_channel_free(c);
+						c = ast_channel_release(c);
 					} else {
 						ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
 					}




More information about the asterisk-commits mailing list