aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-03-24 15:13:20 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2019-03-24 15:13:20 -0400
commitbd9396a0b2d42497f1196af74b327e00cb6af435 (patch)
tree8bd9351a4cc670f092ca0f6970a07ce9c68a9919
parent276d2e6c2d8141f194a26da03b5b79375eb7041b (diff)
downloadpostgresql-bd9396a0b2d42497f1196af74b327e00cb6af435.tar.gz
postgresql-bd9396a0b2d42497f1196af74b327e00cb6af435.zip
Avoid double-free in vacuumlo error path.
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.
-rw-r--r--contrib/vacuumlo/vacuumlo.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index db7a1c47fa1..ac3ff60e814 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -314,7 +314,7 @@ vacuumlo(const char *database, const struct _param *param)
deleted = 0;
- while (1)
+ do
{
res = PQexec(conn, buf);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -352,8 +352,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
@@ -391,7 +390,7 @@ vacuumlo(const char *database, const struct _param *param)
}
PQclear(res);
- }
+ } while (success);
/*
* That's all folks!