Redundant SQL servers accounting problem, FreeRadius 1.1.4

Nicolas Baradakis nbk at sitadelle.com
Wed Mar 21 12:37:03 CET 2007


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: /source/radiusd/src/modules/rlm_sql/drivers/rlm_sql_postgresql/sql_postgresql.c,v
retrieving revision 1.38.4.1
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	1.38.4.1
+++ 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 %s@%s:%s", config->sql_login, config->sql_server, config->sql_db);
 		radlog(L_ERR, "rlm_sql_postgresql: Postgresql error '%s'", PQerrorMessage(pg_sock->conn));
-		PQfinish(pg_sock->conn);
+		sql_close(sqlsocket, config);
 		return SQL_DOWN;
 	}
 

-- 
Nicolas Baradakis




More information about the Freeradius-Users mailing list