[Dovecot] Fix for the consume_results leak

Rainer Weikusat rweikusat at mssgmbh.com
Fri Mar 26 16:50:10 EET 2010


I'm not really comfortable with making non-trivial changes to this
code but here is at least a fix for the PGresult leak (verified to
both apply to 1.2.11 and 2.0.beta4).

-----
--- dovecot/src/lib-sql/driver-pgsql.c	15 Mar 2010 18:18:14 -0000	1.1.1.2
+++ dovecot/src/lib-sql/driver-pgsql.c	26 Mar 2010 14:13:18 -0000	1.1.1.2.4.1
@@ -247,6 +247,17 @@
 	return 0;
 }
 
+static inline int more_results(PGconn *pg)
+{
+	PGresult *pgres;
+
+	pgres = PQgetResult(pg);
+	if (!pgres) return 0;
+
+	PQclear(pgres);
+	return 1;
+}
+
 static void consume_results(struct pgsql_db *db)
 {
 	do {
@@ -255,7 +266,7 @@
 
 		if (PQisBusy(db->pg))
 			return;
-	} while (PQgetResult(db->pg) != NULL);
+	} while (more_results(db->pg));
 
 	if (PQstatus(db->pg) == CONNECTION_BAD)
 		io_remove_closed(&db->io);


More information about the dovecot mailing list