Mercurial > vim
diff src/userfunc.c @ 26053:e861c5aaedd8 v8.2.3560
patch 8.2.3560: using freed memory with lambda
Commit: https://github.com/vim/vim/commit/844fb64a605d60131827503a001b2d1aa232b078
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 23 13:32:30 2021 +0100
patch 8.2.3560: using freed memory with lambda
Problem: Using freed memory with lambda.
Solution: Do not free lines early, keep them until the expression is
finished.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 23 Oct 2021 14:45:04 +0200 |
parents | f773ef3c641d |
children | a968027f8a2c |
line wrap: on
line diff
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -1177,12 +1177,17 @@ lambda_function_body( if (cmdline != NULL) { + garray_T *tfgap = &evalarg->eval_tofree_ga; + // Something comes after the "}". *arg = eap.nextcmd; // "arg" points into cmdline, need to keep the line and free it later. - vim_free(evalarg->eval_tofree_cmdline); - evalarg->eval_tofree_cmdline = cmdline; + if (ga_grow(tfgap, 1) == OK) + { + ((char_u **)(tfgap->ga_data))[tfgap->ga_len++] = cmdline; + evalarg->eval_using_cmdline = TRUE; + } } else *arg = (char_u *)""; @@ -4867,7 +4872,7 @@ ex_return(exarg_T *eap) return; } - CLEAR_FIELD(evalarg); + init_evalarg(&evalarg); evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE; if (eap->skip)