[asterisk-commits] tilghman: branch tilghman/res_odbc_astobj2 r101769 - /team/tilghman/res_odbc_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Feb 1 09:03:45 CST 2008


Author: tilghman
Date: Fri Feb  1 09:03:43 2008
New Revision: 101769

URL: http://svn.digium.com/view/asterisk?view=rev&rev=101769
Log:
Suggested fixes from Russell

Modified:
    team/tilghman/res_odbc_astobj2/res/res_odbc.c

Modified: team/tilghman/res_odbc_astobj2/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/res_odbc_astobj2/res/res_odbc.c?view=diff&rev=101769&r1=101768&r2=101769
==============================================================================
--- team/tilghman/res_odbc_astobj2/res/res_odbc.c (original)
+++ team/tilghman/res_odbc_astobj2/res/res_odbc.c Fri Feb  1 09:03:43 2008
@@ -87,10 +87,9 @@
 		ast_free(class->sanitysql);
 	ao2_ref(class->obj_container, -1);
 	SQLFreeHandle(SQL_HANDLE_ENV, class->env);
-	ast_free(class);
-}
-
-static int return0(const void *obj, const int flags)
+}
+
+static int null_hash_fn(const void *obj, const int flags)
 {
 	return 0;
 }
@@ -314,17 +313,6 @@
 					break;
 				}
 
-				if (cat)
-					ast_copy_string(new->name, cat, sizeof(new->name));
-				if (dsn)
-					ast_copy_string(new->dsn, dsn, sizeof(new->dsn));
-				if (username)
-					new->username = ast_strdup(username);
-				if (password)
-					new->password = ast_strdup(password);
-				if (sanitysql)
-					new->sanitysql = ast_strdup(sanitysql);
-
 				SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &new->env);
 				res = SQLSetEnvAttr(new->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
 
@@ -334,7 +322,7 @@
 					return res;
 				}
 
-				new->obj_container = ao2_container_alloc(1, return0, ao2_match_by_addr);
+				new->obj_container = ao2_container_alloc(1, null_hash_fn, ao2_match_by_addr);
 
 				if (pooling) {
 					new->haspool = pooling;
@@ -349,9 +337,27 @@
 				new->backslash_is_escape = bse ? 1 : 0;
 				new->idlecheck = idlecheck;
 
+				if (cat)
+					ast_copy_string(new->name, cat, sizeof(new->name));
+				if (dsn)
+					ast_copy_string(new->dsn, dsn, sizeof(new->dsn));
+				if (username && !(new->username = ast_strdup(username))) {
+					ao2_ref(new, -1);
+					break;
+				}
+				if (password && !(new->password = ast_strdup(password))) {
+					ao2_ref(new, -1);
+					break;
+				}
+				if (sanitysql && !(new->sanitysql = ast_strdup(sanitysql))) {
+					ao2_ref(new, -1);
+					break;
+				}
+
 				odbc_register_class(new, connect);
 				ast_log(LOG_NOTICE, "Registered ODBC class '%s' dsn->[%s]\n", cat, dsn);
 				ao2_ref(new, -1);
+				new = NULL;
 			}
 		}
 	}
@@ -423,6 +429,7 @@
 			}
 			ast_cli(a->fd, "\n");
 		}
+		ao2_ref(class, -1);
 	}
 
 	return CLI_SUCCESS;
@@ -437,6 +444,7 @@
 	struct odbc_obj *obj;
 	if (class) {
 		ao2_link(class_container, class);
+		/* I still have a reference in the caller, so a deref is NOT missing here. */
 
 		if (connect) {
 			/* Request and release builds a connection */
@@ -629,6 +637,7 @@
 	/* First, mark all to be purged */
 	while ((class = ao2_iterator_next(&aoi))) {
 		class->delme = 1;
+		ao2_ref(class, -1);
 	}
 
 	load_odbc_config();
@@ -657,7 +666,7 @@
 
 static int load_module(void)
 {
-	if (!(class_container = ao2_container_alloc(1, return0, ao2_match_by_addr)))
+	if (!(class_container = ao2_container_alloc(1, null_hash_fn, ao2_match_by_addr)))
 		return AST_MODULE_LOAD_DECLINE;
 	if (load_odbc_config() == -1)
 		return AST_MODULE_LOAD_DECLINE;




More information about the asterisk-commits mailing list