about summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2014-09-29 17:17:26 +0100
committerPeter Stephenson <pws@zsh.org>2014-09-29 17:17:26 +0100
commitf2aaea5cd31fcca6f060e1de0cb1e91c05c716bb (patch)
treed9fa45066808a4aadb1bb633f3f4d0c68c3bbac0 /Src/hist.c
parent546203a770cec329e73781c3c8ab1078390aee72 (diff)
downloadzsh-f2aaea5cd31fcca6f060e1de0cb1e91c05c716bb.tar.gz
zsh-f2aaea5cd31fcca6f060e1de0cb1e91c05c716bb.tar.xz
zsh-f2aaea5cd31fcca6f060e1de0cb1e91c05c716bb.zip
users/19183: improve unlikely error case with fdopen in history code
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c7
1 files changed, 6 insertions, 1 deletions
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