aboutsummaryrefslogtreecommitdiffstats
path: root/cdr
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-06-12 19:40:17 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-06-12 19:40:17 +0000
commit639789106ea1f21f4a15aa3ec0979f7befe18ca2 (patch)
tree29d6fd27c71a5f5d365d3f5d3bef1714485256e9 /cdr
parent3ed7453f0f60a2aa34b68905ad3b946a86013311 (diff)
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. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@69016 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr')
-rw-r--r--cdr/cdr_pgsql.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c
index e8f5b73c1..dd43b45ba 100644
--- a/cdr/cdr_pgsql.c
+++ b/cdr/cdr_pgsql.c
@@ -67,13 +67,13 @@ static int connected = 0;
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);
@@ -153,26 +153,27 @@ static int pgsql_log(struct ast_cdr *cdr)
}
}
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;