]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pgsql: Don't crash in sync queries if db can't be connected to.
authorTimo Sirainen <tss@iki.fi>
Tue, 8 Jul 2008 09:15:49 +0000 (14:45 +0530)
committerTimo Sirainen <tss@iki.fi>
Tue, 8 Jul 2008 09:15:49 +0000 (14:45 +0530)
--HG--
branch : HEAD

src/lib-sql/driver-pgsql.c

index 8dfbb9f0160dfe04c614ba04808cb5b3bcc24e6f..ec22ae3a042b41d0a00b013e6e5dd1f0fee66634 100644 (file)
@@ -560,6 +560,7 @@ static struct sql_result *
 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, const char *query)
        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, const char *query)
        }
        io_loop_destroy(&db->ioloop);
 
-       i_assert(db->io == NULL);
+       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;
+       }
 
-       return db->sync_result;
+       i_assert(db->io == NULL);
+       return result;
 }
 
 static int driver_pgsql_result_next_row(struct sql_result *_result)