From ae01a5e9f8cde646f369bdf9c6cf1f8679204291 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 5 May 2020 22:16:15 -0400 Subject: [PATCH] vim-patch:8.1.1186: readdir() allocates list twice Problem: readdir() allocates list twice. Solution: Remove second allocation. Also check for zero length. https://github.com/vim/vim/commit/334ad415040f9592451ec99498cd99f90d6e33e6 --- src/nvim/eval/funcs.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 217490ad10..c7df1d6753 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -6393,20 +6393,14 @@ static void f_readdir(typval_T *argvars, typval_T *rettv, FunPtr fptr) os_closedir(&dir); } - rettv->vval.v_list = tv_list_alloc(kListLenShouldKnow); - if (rettv->vval.v_list != NULL) { - tv_list_ref(rettv->vval.v_list); + if (rettv->vval.v_list != NULL && ga.ga_len > 0) { sort_strings((char_u **)ga.ga_data, ga.ga_len); for (int i = 0; i < ga.ga_len; i++) { path = ((const char **)ga.ga_data)[i]; tv_list_append_string(rettv->vval.v_list, path, -1); } } - for (int i = 0; i < ga.ga_len; i++) { - xfree(((uint8_t **)ga.ga_data)[i]); - } - - ga_clear(&ga); + ga_clear_strings(&ga); } /*