Merged revisions 77318 via svnmerge from
authorMark Michelson <mmichelson@digium.com>
Thu, 26 Jul 2007 18:31:28 +0000 (18:31 +0000)
committerMark Michelson <mmichelson@digium.com>
Thu, 26 Jul 2007 18:31:28 +0000 (18:31 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r77318 | mmichelson | 2007-07-26 13:30:29 -0500 (Thu, 26 Jul 2007) | 8 lines

Two consecutive calls to PQfinish could occur, meaning free gets called on the same variable twice.
This patch sets the connection to NULL after calls to PQfinish so that the problem does not occur.
Also in this patch, prashant_jois informed me that it is safe to pass a null pointer to PQfinish, so
I have removed the check for conn's existence from my_unload_module.

(closes issue 10295, reported by junky, patched by me with input from prashant_jois)

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@77319 65c4cc65-6c06-0410-ace0-fbb531ad65f3

cdr/cdr_pgsql.c

index 12d9778..82dce65 100644 (file)
@@ -90,6 +90,7 @@ static int pgsql_log(struct ast_cdr *cdr)
                        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);
+                       conn = NULL;
                }
        }
 
@@ -148,6 +149,7 @@ static int pgsql_log(struct ast_cdr *cdr)
                                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);
+                               conn = NULL;
                                connected = 0;
                                ast_mutex_unlock(&pgsql_lock);
                                return -1;
@@ -183,8 +185,7 @@ static int pgsql_log(struct ast_cdr *cdr)
 
 static int my_unload_module(void)
 { 
-       if (conn)
-               PQfinish(conn);
+       PQfinish(conn);
        if (pghostname)
                ast_free(pghostname);
        if (pgdbname)