dovecot-1.2: pgsql: Don't crash in sync queries if db can't be c...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jul 8 12:29:13 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/47483377feb4
changeset: 7968:47483377feb4
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jul 08 14:45:49 2008 +0530
description:
pgsql: Don't crash in sync queries if db can't be connected to.

diffstat:

1 file changed, 10 insertions(+), 3 deletions(-)
src/lib-sql/driver-pgsql.c |   13 ++++++++++---

diffs (38 lines):

diff -r 6d9f2185b9e0 -r 47483377feb4 src/lib-sql/driver-pgsql.c
--- a/src/lib-sql/driver-pgsql.c	Tue Jul 08 13:49:35 2008 +0530
+++ b/src/lib-sql/driver-pgsql.c	Tue Jul 08 14:45:49 2008 +0530
@@ -560,6 +560,7 @@ driver_pgsql_query_s(struct sql_db *_db,
 driver_pgsql_query_s(struct sql_db *_db, const char *query)
 {
         struct pgsql_db *db = (struct pgsql_db *)_db;
+	struct sql_result *result;
 	struct io old_io;
 
 	if (db->queue_to != NULL) {
@@ -585,7 +586,7 @@ driver_pgsql_query_s(struct sql_db *_db,
 	driver_pgsql_query(_db, query, pgsql_query_s_callback, db);
 
 	if (!db->query_finished) {
-		if (db->connected || db->connecting)
+		if ((db->connected || db->connecting) && db->io != NULL)
 			io_loop_run(db->ioloop);
 		else
 			queue_abort_next(db);
@@ -602,9 +603,15 @@ driver_pgsql_query_s(struct sql_db *_db,
 	}
 	io_loop_destroy(&db->ioloop);
 
+	result = db->sync_result;
+	if (result == &sql_not_connected_result) {
+		/* we don't end up in pgsql's free function, so sync_result
+		   won't be set to NULL if we don't do it here. */
+		db->sync_result = NULL;
+	}
+
 	i_assert(db->io == NULL);
-
-	return db->sync_result;
+	return result;
 }
 
 static int driver_pgsql_result_next_row(struct sql_result *_result)


More information about the dovecot-cvs mailing list