Author: mmichelson
Date: Thu Jul 26 13:30:29 2007
New Revision: 77318

URL: http://svn.digium.com/view/asterisk?view=rev&rev=77318
Log:
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)


Modified:
    branches/1.4/cdr/cdr_pgsql.c

Modified: branches/1.4/cdr/cdr_pgsql.c
URL: 
http://svn.digium.com/view/asterisk/branches/1.4/cdr/cdr_pgsql.c?view=diff&rev=77318&r1=77317&r2=77318
==============================================================================
--- branches/1.4/cdr/cdr_pgsql.c (original)
+++ branches/1.4/cdr/cdr_pgsql.c Thu Jul 26 13:30:29 2007
@@ -89,6 +89,7 @@
                        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;
                }
        }
 
@@ -149,6 +150,7 @@
                                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;
@@ -184,8 +186,7 @@
 
 static int my_unload_module(void)
 { 
-       if (conn)
-               PQfinish(conn);
+       PQfinish(conn);
        if (pghostname)
                free(pghostname);
        if (pgdbname)


_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

svn-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/svn-commits

Reply via email to