From 46864467526e2f426b758d2f2e01e2604e5f4ce5 Mon Sep 17 00:00:00 2001 From: qwell Date: Wed, 20 Jun 2007 23:32:39 +0000 Subject: Fix some potential memory leaks in cdr_pgsql. Issue 10020, patch by my, with credit to prashant_jois for pointing out the problem. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@70612 f38db490-d61c-443f-a65b-d21fe96a405b --- cdr/cdr_pgsql.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cdr/cdr_pgsql.c') diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c index 45e3e4af4..1521adaf0 100644 --- a/cdr/cdr_pgsql.c +++ b/cdr/cdr_pgsql.c @@ -86,8 +86,9 @@ static int pgsql_log(struct ast_cdr *cdr) connected = 1; } else { pgerror = PQerrorMessage(conn); + PQfinish(conn); ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s. Calls will not be logged!\n", pghostname); - ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror); + ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror); } } @@ -145,6 +146,7 @@ static int pgsql_log(struct ast_cdr *cdr) connected = 1; } else { pgerror = PQerrorMessage(conn); + PQfinish(conn); ast_log(LOG_ERROR, "cdr_pgsql: Unable to reconnect to database server %s. Calls will not be logged!\n", pghostname); ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror); connected = 0; @@ -162,6 +164,7 @@ static int pgsql_log(struct ast_cdr *cdr) if (PQstatus(conn) == CONNECTION_OK) { ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n"); connected = 1; + PQclear(result); result = PQexec(conn, sqlcmd); if (PQresultStatus(result) != PGRES_COMMAND_OK) { pgerror = PQresultErrorMessage(result); -- cgit v1.2.3