diff --git a/src/warc.c b/src/warc.c index 3482cf3b..5ebd04d7 100644 --- a/src/warc.c +++ b/src/warc.c @@ -203,6 +203,7 @@ warc_write_start_record (void) /* Start a GZIP stream, if required. */ if (opt.warc_compression_enabled) { + int dup_fd; /* Record the starting offset of the new record. */ warc_current_gzfile_offset = ftello (warc_current_file); @@ -214,13 +215,23 @@ warc_write_start_record (void) fflush (warc_current_file); /* Start a new GZIP stream. */ - warc_current_gzfile = gzdopen (dup (fileno (warc_current_file)), "wb9"); + dup_fd = dup (fileno (warc_current_file)); + if (dup_fd < 0) + { + logprintf (LOG_NOTQUIET, +_("Error duplicating WARC file file descriptor.\n")); + warc_write_ok = false; + return false; + } + + warc_current_gzfile = gzdopen (dup_fd, "wb9"); warc_current_gzfile_uncompressed_size = 0; if (warc_current_gzfile == NULL) { logprintf (LOG_NOTQUIET, _("Error opening GZIP stream to WARC file.\n")); + close (dup_fd); warc_write_ok = false; return false; }