dovecot-2.0: pgsql: Don't leak memory if query returns multiple ...

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 27 04:06:23 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/5a6aaf88f15c
changeset: 11003:5a6aaf88f15c
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Mar 27 04:06:20 2010 +0200
description:
pgsql: Don't leak memory if query returns multiple results.
Found by Rainer Weikusat.

diffstat:

 src/lib-sql/driver-pgsql.c |  13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diffs (33 lines):

diff -r fdb352eecdac -r 5a6aaf88f15c src/lib-sql/driver-pgsql.c
--- a/src/lib-sql/driver-pgsql.c	Sat Mar 27 03:44:31 2010 +0200
+++ b/src/lib-sql/driver-pgsql.c	Sat Mar 27 04:06:20 2010 +0200
@@ -249,13 +249,17 @@
 
 static void consume_results(struct pgsql_db *db)
 {
-	do {
-		if (!PQconsumeInput(db->pg))
-			break;
+	PGresult *pgres;
 
+	while (PQconsumeInput(db->pg)) {
 		if (PQisBusy(db->pg))
 			return;
-	} while (PQgetResult(db->pg) != NULL);
+
+		pgres = PQgetResult(db->pg);
+		if (pgres == NULL)
+			break;
+		PQclear(pgres);
+	}
 
 	if (PQstatus(db->pg) == CONNECTION_BAD)
 		io_remove_closed(&db->io);
@@ -280,6 +284,7 @@
 
 	if (result->pgres != NULL) {
 		PQclear(result->pgres);
+		result->pgres = NULL;
 
 		/* we'll have to read the rest of the results as well */
 		i_assert(db->io == NULL);


More information about the dovecot-cvs mailing list