From: Tom Lane Date: Wed, 18 Dec 2024 03:31:26 +0000 (-0500) Subject: Fix memory leak in pg_restore with zstd-compressed data. X-Git-Tag: REL_16_7~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8cfff087b55f6688e2f3b5f1ba303dc5fb8222c6;p=thirdparty%2Fpostgresql.git Fix memory leak in pg_restore with zstd-compressed data. EndCompressorZstd() neglected to free everything. This was most visible with a lot of large objects in the dump. Per report from Tomasz Szypowski. Back-patch to v16 where this code came in. Discussion: https://postgr.es/m/DU0PR04MB94193D038A128EF989F922D199042@DU0PR04MB9419.eurprd04.prod.outlook.com --- diff --git a/src/bin/pg_dump/compress_zstd.c b/src/bin/pg_dump/compress_zstd.c index 82e3310100f..078be03387e 100644 --- a/src/bin/pg_dump/compress_zstd.c +++ b/src/bin/pg_dump/compress_zstd.c @@ -137,9 +137,10 @@ EndCompressorZstd(ArchiveHandle *AH, CompressorState *cs) Assert(zstdcs->dstream == NULL); _ZstdWriteCommon(AH, cs, true); ZSTD_freeCStream(zstdcs->cstream); - pg_free(zstdcs->output.dst); } + /* output buffer may be allocated in either mode */ + pg_free(zstdcs->output.dst); pg_free(zstdcs); }