mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-25 23:21:26 +03:00
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
This commit is contained in:
parent
7746f2f609
commit
31aa38158a
14
xmlIO.c
14
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user