[asterisk-commits] trunk r21600 - in /trunk: ./ cdr/cdr_odbc.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Apr 19 11:56:40 MST 2006


Author: tilghman
Date: Wed Apr 19 13:56:38 2006
New Revision: 21600

URL: http://svn.digium.com/view/asterisk?rev=21600&view=rev
Log:
Merged revisions 21597 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r21597 | tilghman | 2006-04-19 13:43:17 -0500 (Wed, 19 Apr 2006) | 2 lines

Bug 6553 - plug memory leaks when ODBC connection is down

........

Modified:
    trunk/   (props changed)
    trunk/cdr/cdr_odbc.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.2-merged' - no diff available.

Modified: trunk/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_odbc.c?rev=21600&r1=21599&r2=21600&view=diff
==============================================================================
--- trunk/cdr/cdr_odbc.c (original)
+++ trunk/cdr/cdr_odbc.c Wed Apr 19 13:56:38 2006
@@ -78,12 +78,17 @@
 static SQLHDBC	ODBC_con;			/* global ODBC Connection Handle */
 static SQLHSTMT	ODBC_stmt;			/* global ODBC Statement Handle */
 
+static void odbc_disconnect(void)
+{
+	SQLDisconnect(ODBC_con);
+	SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
+	SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
+	connected = 0;
+}
+
 static int odbc_log(struct ast_cdr *cdr)
 {
-	SQLINTEGER ODBC_err;
-	short int ODBC_mlen;
 	int ODBC_res;
-	char ODBC_msg[200], ODBC_stat[10];
 	char sqlcmd[2048] = "", timestr[128];
 	int res = 0;
 	struct tm tm;
@@ -111,7 +116,7 @@
 	if (!connected) {
 		res = odbc_init();
 		if (res < 0) {
-			connected = 0;
+			odbc_disconnect();
 			ast_mutex_unlock(&odbc_lock);
 			return 0;
 		}				
@@ -122,9 +127,8 @@
 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 		if (option_verbose > 10)
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Failure in AllocStatement %d\n", ODBC_res);
-		SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, (unsigned char *)ODBC_stat, &ODBC_err, (unsigned char *)ODBC_msg, 100, &ODBC_mlen);
-		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);	
-		connected = 0;
+		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+		odbc_disconnect();
 		ast_mutex_unlock(&odbc_lock);
 		return 0;
 	}
@@ -138,9 +142,8 @@
 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 		if (option_verbose > 10)
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in PREPARE %d\n", ODBC_res);
-		SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, (unsigned char *)ODBC_stat, &ODBC_err, (unsigned char *)ODBC_msg, 100, &ODBC_mlen);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
-		connected = 0;
+		odbc_disconnect();
 		ast_mutex_unlock(&odbc_lock);
 		return 0;
 	}
@@ -173,13 +176,14 @@
 		if (res < 0) {
 			if (option_verbose > 10)		
 				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
-			res = odbc_init();
 			if (option_verbose > 10)
 				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn);
+			SQLDisconnect(ODBC_con);
+			res = odbc_init();
 			if (res < 0) {
 				if (option_verbose > 10)
 					ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: %s has gone away!\n", dsn);
-				connected = 0;
+				odbc_disconnect();
 			} else {
 				if (option_verbose > 10)
 					ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n");
@@ -211,10 +215,7 @@
 		if (option_verbose > 10)
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Disconnecting from %s\n", dsn);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
-		SQLDisconnect(ODBC_con);
-		SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
-		SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
-		connected = 0;
+		odbc_disconnect();
 	}
 	if (dsn) {
 		if (option_verbose > 10)
@@ -383,7 +384,7 @@
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res);
 		SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, (unsigned char *)ODBC_stat, &ODBC_err, (unsigned char *)ODBC_msg, 100, &ODBC_mlen);
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
-		connected = 0;
+		odbc_disconnect();
 		return -1;
 	} else {
 		if (option_verbose > 10)
@@ -395,10 +396,7 @@
 
 static int odbc_init(void)
 {
-	SQLINTEGER ODBC_err;
-	short int ODBC_mlen;
 	int ODBC_res;
-	char ODBC_msg[200], ODBC_stat[10];
 
 	if (ODBC_env == SQL_NULL_HANDLE || connected == 0) {
 		ODBC_res = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &ODBC_env);
@@ -438,7 +436,7 @@
 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 		if (option_verbose > 10)
 			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error SQLConnect %d\n", ODBC_res);
-		SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, (unsigned char *)ODBC_stat, &ODBC_err, (unsigned char *)ODBC_msg, 100, &ODBC_mlen);
+		SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
 		SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
 		connected = 0;
 		return -1;



More information about the asterisk-commits mailing list