[svn-commits] russell: trunk r69017 - in /trunk: ./ cdr/cdr_pgsql.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Jun 12 12:40:42 MST 2007


Author: russell
Date: Tue Jun 12 14:40:41 2007
New Revision: 69017

URL: http://svn.digium.com/view/asterisk?view=rev&rev=69017
Log:
Merged revisions 69016 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r69016 | russell | 2007-06-12 14:40:17 -0500 (Tue, 12 Jun 2007) | 4 lines

Fix a memory leak pointed out by prashant_jois in #asterisk-bugs.  PQclear() was
not called on the result structure after doing a PQexec().  Also, fix up some
formatting in passing.

........

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

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

Modified: trunk/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_pgsql.c?view=diff&rev=69017&r1=69016&r2=69017
==============================================================================
--- trunk/cdr/cdr_pgsql.c (original)
+++ trunk/cdr/cdr_pgsql.c Tue Jun 12 14:40:41 2007
@@ -68,13 +68,13 @@
 AST_MUTEX_DEFINE_STATIC(pgsql_lock);
 
 static PGconn	*conn = NULL;
-static PGresult	*result = NULL;
 
 static int pgsql_log(struct ast_cdr *cdr)
 {
 	struct tm tm;
 	char sqlcmd[2048] = "", timestr[128];
 	char *pgerror;
+	PGresult *result;
 
 	ast_mutex_lock(&pgsql_lock);
 
@@ -154,26 +154,27 @@
 			}
 		}
 		result = PQexec(conn, sqlcmd);
-		if ( PQresultStatus(result) != PGRES_COMMAND_OK) {
-                        pgerror = PQresultErrorMessage(result);
+		if (PQresultStatus(result) != PGRES_COMMAND_OK) {
+			pgerror = PQresultErrorMessage(result);
 			ast_log(LOG_ERROR,"cdr_pgsql: Failed to insert call detail record into database!\n");
-                        ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
+			ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
 			ast_log(LOG_ERROR,"cdr_pgsql: Connection may have been lost... attempting to reconnect.\n");
 			PQreset(conn);
 			if (PQstatus(conn) == CONNECTION_OK) {
 				ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
 				connected = 1;
 				result = PQexec(conn, sqlcmd);
-				if ( PQresultStatus(result) != PGRES_COMMAND_OK)
-				{
+				if (PQresultStatus(result) != PGRES_COMMAND_OK) {
 					pgerror = PQresultErrorMessage(result);
 					ast_log(LOG_ERROR,"cdr_pgsql: HARD ERROR!  Attempted reconnection failed.  DROPPING CALL RECORD!\n");
 					ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
 				}
 			}
 			ast_mutex_unlock(&pgsql_lock);
+			PQclear(result);
 			return -1;
 		}
+		PQclear(result);
 	}
 	ast_mutex_unlock(&pgsql_lock);
 	return 0;



More information about the svn-commits mailing list