[asterisk-commits] eliel: branch eliel/data_retrieval r183695 - /team/eliel/data_retrieval/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 23 10:27:47 CDT 2009


Author: eliel
Date: Mon Mar 23 10:27:43 2009
New Revision: 183695

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183695
Log:
Fix some issues regarding refcounting and returned error values.

Modified:
    team/eliel/data_retrieval/main/data.c

Modified: team/eliel/data_retrieval/main/data.c
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/main/data.c?view=diff&rev=183695&r1=183694&r2=183695
==============================================================================
--- team/eliel/data_retrieval/main/data.c (original)
+++ team/eliel/data_retrieval/main/data.c Mon Mar 23 10:27:43 2009
@@ -220,6 +220,7 @@
 {
 	char *node_name, *rpath;
 	struct data_node *child;
+	int ret = 0;
 
 	rpath = strdupa(path);
 	if (!rpath) {
@@ -233,23 +234,22 @@
 
 	child = data_find_child(parent, node_name);
 	if (!child) {
-		ast_log(LOG_ERROR, "Unable to find node '%s'\n", node_name);
 		return -1;
 	}
 
 	/* if this is not a terminal node. */
 	if (!child->read && rpath) {
-		data_nodes_release(child->children, rpath);
+		ret = data_nodes_release(child->children, rpath);
 	}
 
 	/* if this node is empty, unlink it. */
-	if (!ao2_container_count(child->children)) {
+	if (!ret && !ao2_container_count(child->children)) {
 		ao2_unlink(parent, child);
 	}
 
 	ao2_ref(child, -1);
 
-	return 0;
+	return ret;
 }
 
 /*!
@@ -283,9 +283,10 @@
 
 	if (rpath) {
 		ret = data_nodes_create(child->children, rpath);
-	}
-
-	ao2_ref(child, -1);
+		if (ret) {
+			ao2_ref(child, -1);
+		}
+	}
 
 	return ret ? ret : child;
 }
@@ -383,8 +384,18 @@
 		data_unlock();
 		return -1;
 	}
+
+	if (ao2_container_count(node->children)) {
+		ast_log(LOG_ERROR, "The node '%s' was already registered. We were unable to register %s.\n", node->name, path);
+		ao2_ref(node, -1);
+		data_unlock();
+		return -1;
+	}
+
 	/* add handler to that node. */
 	node->read = read_handler;
+
+	ao2_ref(node, -1);
 
 	data_unlock();
 
@@ -399,7 +410,11 @@
 	ret = data_nodes_release(root_data, path);
 	data_unlock();
 
-	return 0;
+	if (ret) {
+		ast_log(LOG_ERROR, "Unable to unregister %s\n", path);
+	}
+
+	return ret;
 }
 
 struct ast_data *ast_data_get(const char *path)
@@ -445,10 +460,8 @@
 	}
 
 	ast_data_register("asterisk/pepe/prueba", test_data_provider);
-	ast_data_register("asterisk/pepe/jose", test_data_provider);
 
 	ast_data_unregister("asterisk/pepe/prueba");
-	ast_data_unregister("asterisk/pepe/jose");
 
 	ast_data_register("asterisk/pepe/prueba", test_data_provider);
 	ast_data_unregister("asterisk/pepe/prueba");




More information about the asterisk-commits mailing list