]> granicus.if.org Git - postgresql/commitdiff
Avoid double-free in vacuumlo error path.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 24 Mar 2019 19:13:21 +0000 (15:13 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 24 Mar 2019 19:13:21 +0000 (15:13 -0400)
The code would do "PQclear(res)" twice if lo_unlink failed, evidently
due to careless thinking about how far out a "break" would break.
Remove the extra PQclear and adjust the loop logic so that we'll fall
out of both levels of loop after an error, as was clearly the intent.

Spotted by Coverity.  I have no idea why it took this long to notice,
since the bug has been there since commit 67ccbb080.  Accordingly,
back-patch to all supported branches.

contrib/vacuumlo/vacuumlo.c

index fa51e33f5d4c6cb0940be66db1b1450f1a725d5f..ce5489f370b6e8cebea70a60a9fc182ebc111224 100644 (file)
@@ -311,7 +311,7 @@ vacuumlo(const char *database, const struct _param * param)
 
        deleted = 0;
 
-       while (1)
+       do
        {
                res = PQexec(conn, buf);
                if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -349,8 +349,7 @@ vacuumlo(const char *database, const struct _param * param)
                                        if (PQtransactionStatus(conn) == PQTRANS_INERROR)
                                        {
                                                success = false;
-                                               PQclear(res);
-                                               break;
+                                               break;  /* out of inner for-loop */
                                        }
                                }
                                else
@@ -388,7 +387,7 @@ vacuumlo(const char *database, const struct _param * param)
                }
 
                PQclear(res);
-       }
+       } while (success);
 
        /*
         * That's all folks!