[asterisk-commits] mjordan: branch 1.8 r348888 - /branches/1.8/cel/cel_pgsql.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Dec 22 16:31:50 CST 2011
Author: mjordan
Date: Thu Dec 22 16:31:46 2011
New Revision: 348888
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=348888
Log:
Fix for memory leaks / cleanup in cel_pgsql
There were a number of issues in cel_pgsql's pgsql_log method:
* If either sql or sql2 could not be allocated, the method would return while
the pgsql_lock was still locked
* If the execution of the log statement succeeded, the sql and sql2 structs
were never free'd
* Reconnection successes were logged as ERRORs. In general, the severity of
several logging statements was reduced
(closes issue ASTERISK-18879)
Reported by: Niolas Bouliane
Tested by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/1624/
Modified:
branches/1.8/cel/cel_pgsql.c
Modified: branches/1.8/cel/cel_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cel/cel_pgsql.c?view=diff&rev=348888&r1=348887&r2=348888
==============================================================================
--- branches/1.8/cel/cel_pgsql.c (original)
+++ branches/1.8/cel/cel_pgsql.c Thu Dec 22 16:31:46 2011
@@ -145,13 +145,7 @@
int first = 1;
if (!sql || !sql2) {
- if (sql) {
- ast_free(sql);
- }
- if (sql2) {
- ast_free(sql2);
- }
- return;
+ goto ast_log_cleanup;
}
ast_str_set(&sql, 0, "INSERT INTO %s (", table);
@@ -289,10 +283,10 @@
if (PQstatus(conn) == CONNECTION_OK) {
connected = 1;
} else {
- ast_log(LOG_ERROR, "Connection was lost... attempting to reconnect.\n");
+ ast_log(LOG_WARNING, "Connection was lost... attempting to reconnect.\n");
PQreset(conn);
if (PQstatus(conn) == CONNECTION_OK) {
- ast_log(LOG_ERROR, "Connection reestablished.\n");
+ ast_log(LOG_NOTICE, "Connection reestablished.\n");
connected = 1;
} else {
pgerror = PQerrorMessage(conn);
@@ -301,21 +295,18 @@
PQfinish(conn);
conn = NULL;
connected = 0;
- ast_mutex_unlock(&pgsql_lock);
- ast_free(sql);
- ast_free(sql2);
- return;
+ goto ast_log_cleanup;
}
}
result = PQexec(conn, ast_str_buffer(sql));
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
pgerror = PQresultErrorMessage(result);
- ast_log(LOG_ERROR, "Failed to insert call detail record into database!\n");
- ast_log(LOG_ERROR, "Reason: %s\n", pgerror);
- ast_log(LOG_ERROR, "Connection may have been lost... attempting to reconnect.\n");
+ ast_log(LOG_WARNING, "Failed to insert call detail record into database!\n");
+ ast_log(LOG_WARNING, "Reason: %s\n", pgerror);
+ ast_log(LOG_WARNING, "Connection may have been lost... attempting to reconnect.\n");
PQreset(conn);
if (PQstatus(conn) == CONNECTION_OK) {
- ast_log(LOG_ERROR, "Connection reestablished.\n");
+ ast_log(LOG_NOTICE, "Connection reestablished.\n");
connected = 1;
PQclear(result);
result = PQexec(conn, ast_str_buffer(sql));
@@ -325,14 +316,16 @@
ast_log(LOG_ERROR, "Reason: %s\n", pgerror);
}
}
- ast_mutex_unlock(&pgsql_lock);
PQclear(result);
- ast_free(sql);
- ast_free(sql2);
- return;
- }
- ast_mutex_unlock(&pgsql_lock);
- }
+ goto ast_log_cleanup;
+ }
+
+ast_log_cleanup:
+ ast_free(sql);
+ ast_free(sql2);
+ }
+
+ ast_mutex_unlock(&pgsql_lock);
}
static int my_unload_module(void)
More information about the asterisk-commits
mailing list