Commit 31aa3815 authored by Philip Withnall's avatar Philip Withnall Committed by Daniel Veillard

xmlIO: Fix an FD leak on gzdopen() failure

According to the documentation, gzdopen() does not close the FD on
failure (but does effectively close it on success, since gzclose()
closes it).

Coverity issues: #60440, #60441

https://bugzilla.gnome.org/show_bug.cgi?id=731990
parent 7746f2f6
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment