From b1fca4862038072887a86a98a7948e3c05f173b3 Mon Sep 17 00:00:00 2001 From: delphij Date: Thu, 9 Aug 2018 02:27:18 +0000 Subject: [PATCH] MFC r336121+r336127(cem): Don't delete outfile unconditionally. --- usr.bin/gzip/gzip.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c index de26ba638b0..03c5c63bc1c 100644 --- a/usr.bin/gzip/gzip.c +++ b/usr.bin/gzip/gzip.c @@ -1424,6 +1424,7 @@ file_uncompress(char *file, char *outfile, size_t outsize) unsigned char header1[4]; enum filetype method; int fd, ofd, zfd = -1; + int error; size_t in_size; #ifndef SMALL ssize_t rv; @@ -1597,14 +1598,21 @@ file_uncompress(char *file, char *outfile, size_t outsize) size = zuncompress(in, out, NULL, 0, NULL); /* need to fclose() if ferror() is true... */ - if (ferror(in) | fclose(in)) { - maybe_warn("failed infile fclose"); - unlink(outfile); + error = ferror(in); + if (error | fclose(in)) { + if (error) + maybe_warn("failed infile"); + else + maybe_warn("failed infile fclose"); + if (cflag == 0) + unlink(outfile); (void)fclose(out); + goto lose; } if (fclose(out) != 0) { maybe_warn("failed outfile fclose"); - unlink(outfile); + if (cflag == 0) + unlink(outfile); goto lose; } break; -- 2.45.0