pgsql: pg_receivewal: Fix resource leaks and error reporting during cle

Started by Fujii Masao9 days ago1 messagescommitters
Jump to latest
#1Fujii Masao
fujii@postgresql.org

pg_receivewal: Fix resource leaks and error reporting during cleanup

Failures while finalizing LZ4 compression or writing the final compressed
data could leak a file descriptor and memory. Without --no-loop,
repeated failures across reconnects could accumulate these resources.

This happened because dir_close() returned immediately on these failures,
skipping the code that closes the file and releases its associated
resources. Fix this by closing the file and executing the common cleanup
code before returning.

Backpatch to all supported versions.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: /messages/by-id/CAHGQGwHfCrEogr6=wr0nCkQevAJ9A3HBqQRjT9iJryO7EjF6Lw@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/bf700a0e9c8a48f1dd1e8e09c300c5e584c44a23

Modified Files
--------------
src/bin/pg_basebackup/receivelog.c | 13 ++++++++++---
src/bin/pg_basebackup/walmethods.c | 9 ++++++---
2 files changed, 16 insertions(+), 6 deletions(-)