diff options
-rw-r--r-- | archival/gunzip.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c index 032b43c2c..83ed5e84a 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c | |||
@@ -75,7 +75,7 @@ static int gunzip_file (const char *path, int flags) | |||
75 | { | 75 | { |
76 | FILE *in_file, *out_file; | 76 | FILE *in_file, *out_file; |
77 | struct stat stat_buf; | 77 | struct stat stat_buf; |
78 | const char *delete_path; | 78 | const char *delete_path = NULL; |
79 | char *out_path = NULL; | 79 | char *out_path = NULL; |
80 | 80 | ||
81 | if (path == NULL || strcmp (path, "-") == 0) { | 81 | if (path == NULL || strcmp (path, "-") == 0) { |
@@ -142,8 +142,10 @@ static int gunzip_file (const char *path, int flags) | |||
142 | delete_path = out_path; | 142 | delete_path = out_path; |
143 | } | 143 | } |
144 | 144 | ||
145 | fclose(out_file); | 145 | if (out_file != stdout) |
146 | fclose(in_file); | 146 | fclose(out_file); |
147 | if (in_file != stdin) | ||
148 | fclose(in_file); | ||
147 | 149 | ||
148 | if (delete_path && !(flags & gunzip_test)) { | 150 | if (delete_path && !(flags & gunzip_test)) { |
149 | if (unlink(delete_path) < 0) { | 151 | if (unlink(delete_path) < 0) { |
@@ -194,10 +196,11 @@ extern int gunzip_main(int argc, char **argv) | |||
194 | if (optind == argc) { | 196 | if (optind == argc) { |
195 | if (gunzip_file (NULL, flags) < 0) | 197 | if (gunzip_file (NULL, flags) < 0) |
196 | status = EXIT_FAILURE; | 198 | status = EXIT_FAILURE; |
197 | } else | 199 | } else { |
198 | for (i = optind; i < argc; i++) | 200 | for (i = optind; i < argc; i++) { |
199 | if (gunzip_file (argv[i], flags) < 0) | 201 | if (gunzip_file (argv[i], flags) < 0) |
200 | status = EXIT_FAILURE; | 202 | status = EXIT_FAILURE; |
201 | 203 | } | |
204 | } | ||
202 | return status; | 205 | return status; |
203 | } | 206 | } |