summary refs log tree commit diff
path: root/Src/utils.c
diff options
context:
space:
mode:
authorKamil Dudka <kdudka@redhat.com>2018-11-07 14:04:56 +0100
committerPeter Stephenson <p.stephenson@samsung.com>2018-11-09 11:06:08 +0000
commitd50e204b0c4c10164a711bf640500e46987de9c3 (patch)
tree5878494b8fa092517e379132089796971bb1d70a /Src/utils.c
parente27175c7c8cdfeb4e28d4ff21eb51aa003d70a03 (diff)
downloadzsh-d50e204b0c4c10164a711bf640500e46987de9c3.tar.gz
zsh-d50e204b0c4c10164a711bf640500e46987de9c3.tar.xz
zsh-d50e204b0c4c10164a711bf640500e46987de9c3.zip
43790: failed mailstat could leak memory
Diffstat (limited to 'Src/utils.c')
-rw-r--r--Src/utils.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/Src/utils.c b/Src/utils.c
index 914e30c5c..e43a3cdb4 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -7459,19 +7459,28 @@ mailstat(char *path, struct stat *st)
 
        /* See if cur/ is present */
        dir = appstr(ztrdup(path), "/cur");
-       if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
+       if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) {
+	   zsfree(dir);
+	   return 0;
+       }
        st_ret.st_atime = st_tmp.st_atime;
 
        /* See if tmp/ is present */
        dir[plen] = 0;
        dir = appstr(dir, "/tmp");
-       if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
+       if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) {
+	   zsfree(dir);
+	   return 0;
+       }
        st_ret.st_mtime = st_tmp.st_mtime;
 
        /* And new/ */
        dir[plen] = 0;
        dir = appstr(dir, "/new");
-       if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
+       if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) {
+	   zsfree(dir);
+	   return 0;
+       }
        st_ret.st_mtime = st_tmp.st_mtime;
 
 #if THERE_IS_EXACTLY_ONE_MAILDIR_IN_MAILPATH
@@ -7483,6 +7492,7 @@ mailstat(char *path, struct stat *st)
            st_tmp.st_atime == st_new_last.st_atime &&
            st_tmp.st_mtime == st_new_last.st_mtime) {
 	   *st = st_ret_last;
+	   zsfree(dir);
 	   return 0;
        }
        st_new_last = st_tmp;