[Dovecot] Fix for the consume_results leak
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);
On Fri, 2010-03-26 at 15:50 +0100, Rainer Weikusat wrote:
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).
Thanks. I did a slightly different change though: http://hg.dovecot.org/dovecot-2.0/rev/5a6aaf88f15c
(the extra result->pgres = NULL probably doesn't fix anything, but avoids potential problems and it wasn't worth a separate commit :)
Timo Sirainen tss@iki.fi writes:
On Fri, 2010-03-26 at 15:50 +0100, Rainer Weikusat wrote:
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).
Thanks. I did a slightly different change though: http://hg.dovecot.org/dovecot-2.0/rev/5a6aaf88f15c
That was the first idea I had, but I thought that the original layout of the loop (loop until all results have been dealt with) made more sense. Since there didn't seemed to be a sensible way to do this without goto (some people strongly object to :->), I then had the idea that this should really be a problem for the compiler and wrote the inline routine which ended up creating exactly the 'loop while PQconsumeInput didn't return an error'-loop in machine code.
participants (2)
-
Rainer Weikusat
-
Timo Sirainen