From 82b029cbb00dbe9649824f7795c177974955d683 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 3 Feb 2025 10:45:50 +0800 Subject: vim-patch:9.0.1142: crash and/or memory leak when redefining function Problem: Crash and/or memory leak when redefining function after error. Solution: Clear pointer after making a copy. Clear arrays on failure. (closes vim/vim#11774) https://github.com/vim/vim/commit/f057171d8b562c72334fd7c15c89ff787358ce3a Co-authored-by: Bram Moolenaar --- src/nvim/eval/userfunc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 3538493159..6eaccbae62 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2918,13 +2918,14 @@ void ex_function(exarg_T *eap) goto ret_free; erret: - ga_clear_strings(&newargs); - ga_clear_strings(&default_args); if (fp != NULL) { + // these were set to "newargs" and "default_args", which are cleared below ga_init(&fp->uf_args, (int)sizeof(char *), 1); ga_init(&fp->uf_def_args, (int)sizeof(char *), 1); } errret_2: + ga_clear_strings(&newargs); + ga_clear_strings(&default_args); ga_clear_strings(&newlines); if (free_fp) { xfree(fp); -- cgit