# HG changeset patch # User Timo Sirainen # Date 1269655580 -7200 # Node ID a39372cd040cda34715299a1809af5a310e4212e # Parent 0cf38dcd8ced2b280001a05efd162b7700b6193e pgsql: Don't leak memory if query returns multiple results. Found by Rainer Weikusat. diff -r 0cf38dcd8ced -r a39372cd040c src/lib-sql/driver-pgsql.c --- a/src/lib-sql/driver-pgsql.c Sat Mar 27 03:54:00 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);