Alexander V. Klepikov wrote:

> I did not find any information about what is going on when database or SQL 
> server suddenly comes down, but it looks like pg_sock->conn is freed when 
> connection to DB became broken. And pg_sock->conn != NULL . That's why libpq 
> crashes when PQfinish(pg_sock->conn) in sql_close function is called.

It seems to me this is the real cause of the problem: pg_sock->conn becomes
an invalid pointer. The libpq manpage says the PGconn pointer should not be
used after PQfinish has been called.

Please try the following patch:

Index: src/modules/rlm_sql/drivers/rlm_sql_postgresql/sql_postgresql.c
RCS file: 
retrieving revision
diff -u -r1.38.4.1 sql_postgresql.c
--- src/modules/rlm_sql/drivers/rlm_sql_postgresql/sql_postgresql.c     14 Dec 
2005 18:32:03 -0000
+++ src/modules/rlm_sql/drivers/rlm_sql_postgresql/sql_postgresql.c     21 Mar 
2007 11:28:17 -0000
@@ -61,6 +61,7 @@
 /* Prototypes */
 static int sql_store_result(SQLSOCK * sqlsocket, SQL_CONFIG *config);
 static int sql_num_fields(SQLSOCK * sqlsocket, SQL_CONFIG *config);
+static int sql_close(SQLSOCK * sqlsocket, SQL_CONFIG *config);
 /* Internal function. Return true if the postgresql status value
  * indicates successful completion of the query. Return false otherwise
@@ -181,7 +182,7 @@
        if (PQstatus(pg_sock->conn) == CONNECTION_BAD) {
                radlog(L_ERR, "rlm_sql_postgresql: Couldn't connect socket to 
PostgreSQL server [EMAIL PROTECTED]:%s", config->sql_login, config->sql_server, 
                radlog(L_ERR, "rlm_sql_postgresql: Postgresql error '%s'", 
-               PQfinish(pg_sock->conn);
+               sql_close(sqlsocket, config);
                return SQL_DOWN;

Nicolas Baradakis

List info/subscribe/unsubscribe? See

Reply via email to