about summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-04-14 13:42:51 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-04-14 13:42:51 +0000
commit5eb7948f86c518a489be3f4150c6cf588fd58727 (patch)
tree2b4997839d7da8cc998c86096a15262bd76e6c4f /Src/hist.c
parentb1b941c30b6f35697c48555448337fa151df52bf (diff)
downloadzsh-5eb7948f86c518a489be3f4150c6cf588fd58727.tar.gz
zsh-5eb7948f86c518a489be3f4150c6cf588fd58727.tar.xz
zsh-5eb7948f86c518a489be3f4150c6cf588fd58727.zip
24814: suspicious handling of temporary history buffer
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Src/hist.c b/Src/hist.c
index a19c94818..58a8c61ff 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2214,6 +2214,7 @@ savehistfile(char *fn, int err, int writeflags)
 #endif
 	     && sb.st_uid != euid) {
 		free(tmpfile);
+		tmpfile = NULL;
 		if (err) {
 		    if (isset(APPENDHISTORY) || isset(INCAPPENDHISTORY)
 		     || isset(SHAREHISTORY))
@@ -2292,6 +2293,7 @@ savehistfile(char *fn, int err, int writeflags)
 		if (rename(tmpfile, unmeta(fn)) < 0)
 		    zerr("can't rename %s.new to $HISTFILE", fn);
 		free(tmpfile);
+		tmpfile = NULL;
 	    }
 
 	    if (writeflags & HFILE_SKIPOLD
@@ -2317,12 +2319,13 @@ savehistfile(char *fn, int err, int writeflags)
 	ret = -1;
 
     if (ret < 0 && err) {
-	if (tmpfile) {
+	if (tmpfile)
 	    zerr("failed to write history file %s.new: %e", fn, errno);
-	    free(tmpfile);
-	} else
+	else
 	    zerr("failed to write history file %s: %e", fn, errno);
     }
+    if (tmpfile)
+	free(tmpfile);
 
     unlockhistfile(fn);
 }