[asterisk-commits] murf: branch murf/selway r148567 - /team/murf/selway/cdr/cdr_odbc.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 13 14:28:55 CDT 2008


Author: murf
Date: Mon Oct 13 14:28:55 2008
New Revision: 148567

URL: http://svn.digium.com/view/asterisk?view=rev&rev=148567
Log:
Null out pointers after FreeHandle just for safety. Remove the mutex_unlocks in build_query.

Modified:
    team/murf/selway/cdr/cdr_odbc.c

Modified: team/murf/selway/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/team/murf/selway/cdr/cdr_odbc.c?view=diff&rev=148567&r1=148566&r2=148567
==============================================================================
--- team/murf/selway/cdr/cdr_odbc.c (original)
+++ team/murf/selway/cdr/cdr_odbc.c Mon Oct 13 14:28:55 2008
@@ -84,9 +84,12 @@
 
 static void odbc_disconnect(void)
 {
+	ODBC_stmt = SQL_NULL_HANDLE;
 	SQLDisconnect(ODBC_con);
 	SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
+	ODBC_con = SQL_NULL_HANDLE;
 	SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
+	ODBC_env = SQL_NULL_HANDLE;
 	connected = 0;
 }
 
@@ -119,7 +122,7 @@
 		res = odbc_init();
 		if (res < 0) {
 			odbc_disconnect();
-			ast_mutex_unlock(&odbc_lock);
+//			ast_mutex_unlock(&odbc_lock);
 			return;
 		}				
 	}
@@ -130,8 +133,9 @@
 		if (option_verbose > 10)
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Failure in AllocStatement %d\n", ODBC_res);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+		ODBC_stmt = SQL_NULL_HANDLE;
 		odbc_disconnect();
-		ast_mutex_unlock(&odbc_lock);
+//		ast_mutex_unlock(&odbc_lock);
 		return;
 	}
 
@@ -145,8 +149,9 @@
 		if (option_verbose > 10)
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in PREPARE %d\n", ODBC_res);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+		ODBC_stmt = SQL_NULL_HANDLE;
 		odbc_disconnect();
-		ast_mutex_unlock(&odbc_lock);
+//		ast_mutex_unlock(&odbc_lock);
 		return;
 	}
 
@@ -197,6 +202,7 @@
 				if (option_verbose > 10)
 					ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n");
 				SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+				ODBC_stmt = SQL_NULL_HANDLE;
 				build_query(cdr, timestr, sizeof(timestr)); /* what a waste. If we have to reconnect, we have to build a new query */
 				res = odbc_do_query();
 				if (res < 0) {
@@ -210,6 +216,7 @@
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
 	}
 	SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+	ODBC_stmt = SQL_NULL_HANDLE;
 	ast_mutex_unlock(&odbc_lock);
 	return 0;
 }
@@ -221,6 +228,7 @@
 		if (option_verbose > 10)
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Disconnecting from %s\n", dsn);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+		ODBC_stmt = SQL_NULL_HANDLE;
 		odbc_disconnect();
 	}
 	if (dsn) {
@@ -422,6 +430,7 @@
 			if (option_verbose > 10)
 				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error SetEnv\n");
 			SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
+			ODBC_env = SQL_NULL_HANDLE;
 			connected = 0;
 			return -1;
 		}
@@ -432,6 +441,7 @@
 			if (option_verbose > 10)
 				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error AllocHDB %d\n", ODBC_res);
 			SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
+			ODBC_env = SQL_NULL_HANDLE;
 			connected = 0;
 			return -1;
 		}
@@ -446,7 +456,9 @@
 		if (option_verbose > 10)
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error SQLConnect %d\n", ODBC_res);
 		SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
+		ODBC_con = SQL_NULL_HANDLE;
 		SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
+		ODBC_env = SQL_NULL_HANDLE;
 		connected = 0;
 		return -1;
 	} else {




More information about the asterisk-commits mailing list