[asterisk-commits] mmichelson: branch group/CCSS r219950 - in /team/group/CCSS: apps/ include/as...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 23 17:39:09 CDT 2009


Author: mmichelson
Date: Wed Sep 23 17:39:06 2009
New Revision: 219950

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=219950
Log:
Make the ast_cc_interface refcounted.

Honestly, it seems silly to have the ast_cc_interface public.
It really should just be an opaque item inside a tree_item and
a monitor. I think that is something to strive for as a 
"would be nice" item.


Modified:
    team/group/CCSS/apps/app_dial.c
    team/group/CCSS/include/asterisk/ccss.h
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/apps/app_dial.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/apps/app_dial.c?view=diff&rev=219950&r1=219949&r2=219950
==============================================================================
--- team/group/CCSS/apps/app_dial.c (original)
+++ team/group/CCSS/apps/app_dial.c Wed Sep 23 17:39:06 2009
@@ -1820,12 +1820,12 @@
 
 	ast_str_set(&str, 0, "%s@%s", exten, context);
 
-	if (!(cc_interface = ast_calloc(1, sizeof(*cc_interface) + ast_str_strlen(str)))) {
+	if (!(cc_interface = ao2_alloc(sizeof(*cc_interface) + ast_str_strlen(str), ast_cc_interface_destroy))) {
 		return NULL;
 	}
 
 	if (!(tree_item = ast_calloc(1, sizeof(*tree_item)))) {
-		ast_free(cc_interface);
+		ao2_t_ref(cc_interface, -1, "failed to allocate the tree item, so unref the interface");
 		return NULL;
 	}
 
@@ -1921,7 +1921,7 @@
 static struct ast_cc_tree_item *cc_device_tree_item_init(const char * const name, const size_t name_len,
 		const int parent_id, const struct ast_control_cc_payload *cc_data)
 {
-	struct ast_cc_interface *cc_interface = ast_calloc(1, sizeof(*cc_interface) + name_len);
+	struct ast_cc_interface *cc_interface = ao2_alloc(sizeof(*cc_interface) + name_len, ast_cc_interface_destroy);
 	struct ast_cc_tree_item *tree_item;
 
 	if (!cc_interface) {
@@ -1929,13 +1929,12 @@
 	}
 
 	if (!(cc_interface->config_params = ast_cc_config_params_init())) {
-		ast_free(cc_interface);
+		ao2_t_ref(cc_interface, -1, "Failed to allocate config params, unref interface");
 		return NULL;
 	}
 
 	if (!(tree_item = ast_calloc(1, sizeof(*tree_item)))) {
-		ast_free(cc_interface->config_params);
-		ast_free(cc_interface);
+		ao2_t_ref(cc_interface, -1, "Failed to allocate tree item, unref interface");
 		return NULL;
 	}
 

Modified: team/group/CCSS/include/asterisk/ccss.h
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/include/asterisk/ccss.h?view=diff&rev=219950&r1=219949&r2=219950
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Wed Sep 23 17:39:06 2009
@@ -459,6 +459,13 @@
 void ast_cc_interface_tree_destroy(void *cc_interface_tree);
 
 /*!
+ * \brief destructor callback for ast_cc_interface
+ *
+ * \param data The ast_cc_interface to be destroyed
+ */
+void ast_cc_interface_destroy(void *data);
+
+/*!
  * \brief free the components of an ast_cc_tree_item
  *
  * \param tree_item The ast_cc_tree_item to destroy

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=219950&r1=219949&r2=219950
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Wed Sep 23 17:39:06 2009
@@ -449,11 +449,16 @@
 	}
 }
 
+void ast_cc_interface_destroy(void *data)
+{
+	struct ast_cc_interface *interface = data;
+	ast_cc_config_params_destroy(interface->config_params);
+}
+
 void ast_cc_tree_item_destroy(struct ast_cc_tree_item *tree_item)
 {
-		ast_free(tree_item->interface->config_params);
-		ast_free(tree_item->interface);
-		ast_free(tree_item);
+	cc_unref(tree_item->interface, "Unreffing tree's reference to interface");
+	ast_free(tree_item);
 }
 
 void ast_cc_interface_tree_destroy(void *data)
@@ -880,7 +885,9 @@
 		return NULL;
 	}
 
-	monitor->interface = cc_interface;
+	ast_log(LOG_NOTICE, "SANDWICH!\n");
+	monitor->interface = cc_ref(cc_interface, "monitor gains reference to interface");
+	ast_log(LOG_NOTICE, "SANDWICH AGAIN!\n");
 	monitor->callbacks = callbacks;
 	monitor->callbacks->init(monitor, core_id);
 	AST_LIST_HEAD_INIT(&monitor->child_links);




More information about the asterisk-commits mailing list