From b596449c1a5d38f8decf40101313b24c8b2eef70 Mon Sep 17 00:00:00 2001
From: Jianghua Yang <yjhjstz@gmail.com>
Date: Sat, 21 Mar 2026 14:17:05 -0700
Subject: [PATCH] pg_basebackup: add missing close() for incremental manifest
 file

When uploading an incremental manifest to the server, the file
descriptor opened for reading the manifest was never closed after
the upload completed. Since the backup can run for a long time
after this point, the leaked descriptor would remain open for
the entire duration.

Add the missing close() call after the file has been fully read.

Author: Jianghua Yang <yjhjstz@gmail.com>
---
 src/bin/pg_basebackup/pg_basebackup.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index fa169a8d642..630b445cb23 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -1874,6 +1874,8 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
 		if (nbytes < 0)
 			pg_fatal("could not read file \"%s\": %m", incremental_manifest);
 
+		close(fd);
+
 		/* End the COPY operation. */
 		if (PQputCopyEnd(conn, NULL) < 0)
 			pg_fatal("could not send end-of-COPY: %s",
-- 
2.50.1 (Apple Git-155)

