]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pgsql: Don't leak memory if query returns multiple results.
authorTimo Sirainen <tss@iki.fi>
Sat, 27 Mar 2010 02:06:20 +0000 (04:06 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 27 Mar 2010 02:06:20 +0000 (04:06 +0200)
Found by Rainer Weikusat.

--HG--
branch : HEAD

src/lib-sql/driver-pgsql.c

index 05563d075ac4b4a101c1976e85c7cc72a70d7c6d..fdcc936de0a4cdb912d712e0cbdd3204dab30ecd 100644 (file)
@@ -249,13 +249,17 @@ driver_pgsql_get_flags(struct sql_db *db ATTR_UNUSED)
 
 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 @@ static void driver_pgsql_result_free(struct sql_result *_result)
 
        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);