Skip to content

Commit d09c873

Browse files
committed
Fix memory leaks in pg_rewind. Several PQclear() calls were missing.
Originally reported by Vladimir Borodin in the pg_rewind github project, patch by Michael Paquier.
1 parent 9c88e06 commit d09c873

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/bin/pg_rewind/libpq_fetch.c

+5
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ libpqGetFile(const char *filename, size_t *filesize)
350350
memcpy(result, PQgetvalue(res, 0, 0), len);
351351
result[len] = '\0';
352352

353+
PQclear(res);
354+
353355
pg_log(PG_DEBUG, "fetched file \"%s\", length %d\n", filename, len);
354356

355357
if (filesize)
@@ -410,13 +412,15 @@ libpq_executeFileMap(filemap_t *map)
410412
if (PQresultStatus(res) != PGRES_COMMAND_OK)
411413
pg_fatal("could not create temporary table: %s",
412414
PQresultErrorMessage(res));
415+
PQclear(res);
413416

414417
sql = "COPY fetchchunks FROM STDIN";
415418
res = PQexec(conn, sql);
416419

417420
if (PQresultStatus(res) != PGRES_COPY_IN)
418421
pg_fatal("could not send file list: %s",
419422
PQresultErrorMessage(res));
423+
PQclear(res);
420424

421425
for (i = 0; i < map->narray; i++)
422426
{
@@ -464,6 +468,7 @@ libpq_executeFileMap(filemap_t *map)
464468
if (PQresultStatus(res) != PGRES_COMMAND_OK)
465469
pg_fatal("unexpected result while sending file list: %s",
466470
PQresultErrorMessage(res));
471+
PQclear(res);
467472
}
468473

469474
/*

0 commit comments

Comments
 (0)