changeset 16362:514e42de6a1d v8.1.1186

patch 8.1.1186: readdir() allocates list twice commit https://github.com/vim/vim/commit/334ad415040f9592451ec99498cd99f90d6e33e6 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Apr 19 15:20:46 2019 +0200 patch 8.1.1186: readdir() allocates list twice Problem: readdir() allocates list twice. Solution: Remove second allocation. Also check for zero length.
author Bram Moolenaar <Bram@vim.org>
date Fri, 19 Apr 2019 15:30:05 +0200
parents d5dc4a56ba8a
children b3a7fe31f4b5
files src/evalfunc.c src/version.c
diffstat 2 files changed, 5 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -9324,10 +9324,8 @@ f_readdir(typval_T *argvars, typval_T *r
     }
 #endif
 
-    rettv->vval.v_list = list_alloc();
-    if (!failed && rettv->vval.v_list != NULL)
-    {
-	++rettv->vval.v_list->lv_refcount;
+    if (!failed && rettv->vval.v_list != NULL && ga.ga_len > 0)
+    {
 	sort_strings((char_u **)ga.ga_data, ga.ga_len);
 	for (i = 0; i < ga.ga_len; i++)
 	{
@@ -9335,10 +9333,7 @@ f_readdir(typval_T *argvars, typval_T *r
 	    list_append_string(rettv->vval.v_list, p, -1);
 	}
     }
-    for (i = 0; i < ga.ga_len; i++)
-	vim_free(((char_u **)ga.ga_data)[i]);
-
-    ga_clear(&ga);
+    ga_clear_strings(&ga);
 }
 
 /*
--- a/src/version.c
+++ b/src/version.c
@@ -772,6 +772,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1186,
+/**/
     1185,
 /**/
     1184,