1
0
forked from aniani/vim

patch 8.2.2791: Vim9: memory leak when using \=expr in :substitute

Problem:    Vim9: memory leak when using \=expr in :substitute.
Solution:   Do not allocate a new instruction list.
This commit is contained in:
Bram Moolenaar
2021-04-20 21:49:35 +02:00
parent 63276685f9
commit 5c787fb792
2 changed files with 5 additions and 5 deletions

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2791,
/**/ /**/
2790, 2790,
/**/ /**/

View File

@@ -8544,9 +8544,7 @@ compile_substitute(char_u *arg, exarg_T *eap, cctx_T *cctx)
cmd = skipwhite(cmd); cmd = skipwhite(cmd);
trailing_error = *cmd != delimiter && *cmd != NUL; trailing_error = *cmd != delimiter && *cmd != NUL;
instr_count = cctx->ctx_instr.ga_len; if (trailing_error || ga_grow(&cctx->ctx_instr, 1) == FAIL)
instr = ALLOC_MULT(isn_T, instr_count + 1);
if (trailing_error || instr == NULL)
{ {
if (trailing_error) if (trailing_error)
semsg(_(e_trailing_arg), cmd); semsg(_(e_trailing_arg), cmd);
@@ -8559,8 +8557,8 @@ compile_substitute(char_u *arg, exarg_T *eap, cctx_T *cctx)
// Move the generated instructions into the ISN_SUBSTITUTE // Move the generated instructions into the ISN_SUBSTITUTE
// instructions, then restore the list of instructions before // instructions, then restore the list of instructions before
// adding the ISN_SUBSTITUTE instruction. // adding the ISN_SUBSTITUTE instruction.
mch_memmove(instr, cctx->ctx_instr.ga_data, instr_count = cctx->ctx_instr.ga_len;
instr_count * sizeof(isn_T)); instr = cctx->ctx_instr.ga_data;
instr[instr_count].isn_type = ISN_FINISH; instr[instr_count].isn_type = ISN_FINISH;
cctx->ctx_instr = save_ga; cctx->ctx_instr = save_ga;