summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2014-06-20 21:11:40 +0100
committerDaniel Veillard <veillard@redhat.com>2014-07-26 20:13:11 +0800
commit31aa38158a0ec6075749838639775f3c01e01f6c (patch)
treee1882010a5b4e4afc4c9ffd4e4975a1f599d5ab3
parent7746f2f60982889cd836fc23022e426f5a02d883 (diff)
downloadlibxml2-31aa38158a0ec6075749838639775f3c01e01f6c.tar.gz
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
-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);
}