Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bd9396a

Browse files
committed
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 67ccbb0. Accordingly, back-patch to all supported branches.
1 parent 276d2e6 commit bd9396a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

contrib/vacuumlo/vacuumlo.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ vacuumlo(const char *database, const struct _param *param)
314314

315315
deleted = 0;
316316

317-
while (1)
317+
do
318318
{
319319
res = PQexec(conn, buf);
320320
if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -352,8 +352,7 @@ vacuumlo(const char *database, const struct _param *param)
352352
if (PQtransactionStatus(conn) == PQTRANS_INERROR)
353353
{
354354
success = false;
355-
PQclear(res);
356-
break;
355+
break; /* out of inner for-loop */
357356
}
358357
}
359358
else
@@ -391,7 +390,7 @@ vacuumlo(const char *database, const struct _param *param)
391390
}
392391

393392
PQclear(res);
394-
}
393+
} while (success);
395394

396395
/*
397396
* That's all folks!

0 commit comments

Comments
 (0)