Commit bd9396a0 authored by Tom Lane's avatar Tom Lane

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 67ccbb08.  Accordingly,
back-patch to all supported branches.
parent 276d2e6c
...@@ -314,7 +314,7 @@ vacuumlo(const char *database, const struct _param *param) ...@@ -314,7 +314,7 @@ vacuumlo(const char *database, const struct _param *param)
deleted = 0; deleted = 0;
while (1) do
{ {
res = PQexec(conn, buf); res = PQexec(conn, buf);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
...@@ -352,8 +352,7 @@ vacuumlo(const char *database, const struct _param *param) ...@@ -352,8 +352,7 @@ vacuumlo(const char *database, const struct _param *param)
if (PQtransactionStatus(conn) == PQTRANS_INERROR) if (PQtransactionStatus(conn) == PQTRANS_INERROR)
{ {
success = false; success = false;
PQclear(res); break; /* out of inner for-loop */
break;
} }
} }
else else
...@@ -391,7 +390,7 @@ vacuumlo(const char *database, const struct _param *param) ...@@ -391,7 +390,7 @@ vacuumlo(const char *database, const struct _param *param)
} }
PQclear(res); PQclear(res);
} } while (success);
/* /*
* That's all folks! * That's all folks!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment