summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/hist.c7
2 files changed, 9 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index dba06e479..f1fb73ed0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2014-09-29 Peter Stephenson <p.stephenson@samsung.com>
+ * users/19183: Src/hist.c: handle unlikely error case with
+ fdopen() better.
+
* 33276: Src/params.c, Src/zsh.h: safer import of numerical
variables from environment.
diff --git a/Src/hist.c b/Src/hist.c
index d29a65afe..4660fd073 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2593,7 +2593,12 @@ savehistfile(char *fn, int err, int writeflags)
out = NULL;
} else {
int fd = open(tmpfile, O_CREAT | O_WRONLY | O_EXCL, 0600);
- out = fd >= 0 ? fdopen(fd, "w") : NULL;
+ if (fd >=0) {
+ out = fdopen(fd, "w");
+ if (!out)
+ close(fd);
+ } else
+ out = NULL;
}
#ifdef HAVE_FCHMOD