summaryrefslogtreecommitdiff
path: root/xmlIO.c
diff options
context:
space:
mode:
Diffstat (limited to 'xmlIO.c')
-rw-r--r--xmlIO.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/xmlIO.c b/xmlIO.c
index d1544f3d..5baeba33 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -1159,7 +1159,12 @@ xmlGzfileOpen_real (const char *filename) {
gzFile fd;
if (!strcmp(filename, "-")) {
- fd = gzdopen(dup(fileno(stdin)), "rb");
+ int duped_fd = dup(fileno(stdin));
+ fd = gzdopen(duped_fd, "rb");
+ if (fd == Z_NULL) {
+ close(duped_fd); /* gzdOpen() does not close on failure */
+ }
+
return((void *) fd);
}
@@ -1233,7 +1238,12 @@ xmlGzfileOpenW (const char *filename, int compression) {
snprintf(mode, sizeof(mode), "wb%d", compression);
if (!strcmp(filename, "-")) {
- fd = gzdopen(dup(fileno(stdout)), mode);
+ int duped_fd = dup(fileno(stdout));
+ fd = gzdopen(duped_fd, "rb");
+ if (fd == Z_NULL) {
+ close(duped_fd); /* gzdOpen() does not close on failure */
+ }
+
return((void *) fd);
}