aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/pg_basebackup/pg_basebackup.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 556a0af9160..4e12cdb4467 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -1022,7 +1022,20 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
#ifdef HAVE_LIBZ
if (compresslevel != 0)
{
- state.ztarfile = gzdopen(dup(fileno(stdout)), "wb");
+ int fd = dup(fileno(stdout));
+ if (fd < 0)
+ {
+ pg_log_error("could not duplicate stdout: %m");
+ exit(1);
+ }
+
+ state.ztarfile = gzdopen(fd, "wb");
+ if (state.ztarfile == NULL)
+ {
+ pg_log_error("could not open output file: %m");
+ exit(1);
+ }
+
if (gzsetparams(state.ztarfile, compresslevel,
Z_DEFAULT_STRATEGY) != Z_OK)
{