To: vim_dev@googlegroups.com Subject: Patch 8.2.3059 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3059 (after 8.2.3056) Problem: Vim9: memory leak when using lambda. Solution: Do not store the default value strings when skipping. Files: src/userfunc.c *** ../vim-8.2.3058/src/userfunc.c 2021-06-26 21:51:58.510221846 +0200 --- src/userfunc.c 2021-06-26 22:15:43.727214172 +0200 *************** *** 198,204 **** ga_init2(newargs, (int)sizeof(char_u *), 3); if (argtypes != NULL) ga_init2(argtypes, (int)sizeof(char_u *), 3); ! if (default_args != NULL) ga_init2(default_args, (int)sizeof(char_u *), 3); if (varargs != NULL) --- 198,204 ---- ga_init2(newargs, (int)sizeof(char_u *), 3); if (argtypes != NULL) ga_init2(argtypes, (int)sizeof(char_u *), 3); ! if (!skip && default_args != NULL) ga_init2(default_args, (int)sizeof(char_u *), 3); if (varargs != NULL) *************** *** 289,312 **** expr = p; if (eval1(&p, &rettv, NULL) != FAIL) { ! if (ga_grow(default_args, 1) == FAIL) ! goto err_ret; ! ! // trim trailing whitespace ! while (p > expr && VIM_ISWHITE(p[-1])) ! p--; ! c = *p; ! *p = NUL; ! expr = vim_strsave(expr); ! if (expr == NULL) { *p = c; - goto err_ret; } - ((char_u **)(default_args->ga_data)) - [default_args->ga_len] = expr; - default_args->ga_len++; - *p = c; } else mustend = TRUE; --- 289,315 ---- expr = p; if (eval1(&p, &rettv, NULL) != FAIL) { ! if (!skip) { + if (ga_grow(default_args, 1) == FAIL) + goto err_ret; + + // trim trailing whitespace + while (p > expr && VIM_ISWHITE(p[-1])) + p--; + c = *p; + *p = NUL; + expr = vim_strsave(expr); + if (expr == NULL) + { + *p = c; + goto err_ret; + } + ((char_u **)(default_args->ga_data)) + [default_args->ga_len] = expr; + default_args->ga_len++; *p = c; } } else mustend = TRUE; *************** *** 357,363 **** err_ret: if (newargs != NULL) ga_clear_strings(newargs); ! if (default_args != NULL) ga_clear_strings(default_args); return FAIL; } --- 360,366 ---- err_ret: if (newargs != NULL) ga_clear_strings(newargs); ! if (!skip && default_args != NULL) ga_clear_strings(default_args); return FAIL; } *** ../vim-8.2.3058/src/version.c 2021-06-26 21:51:58.514221840 +0200 --- src/version.c 2021-06-26 22:17:18.559029748 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3059, /**/ -- Seen it all, done it all, can't remember most of it. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///