summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-20 21:49:35 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-20 21:49:35 +0200
commit5c787fb7928c4cc1e7d6eec0be1bbd63d903cc8d (patch)
tree09c8a544e430030a226bcedad4fe18c95f528f1c /src/vim9compile.c
parent63276685f90fca8b1a0be3a6734759fa82b7be0c (diff)
downloadvim-git-5c787fb7928c4cc1e7d6eec0be1bbd63d903cc8d.tar.gz
patch 8.2.2791: Vim9: memory leak when using \=expr in :substitutev8.2.2791
Problem: Vim9: memory leak when using \=expr in :substitute. Solution: Do not allocate a new instruction list.
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 279a8c3a3..ade86aa5c 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8544,9 +8544,7 @@ compile_substitute(char_u *arg, exarg_T *eap, cctx_T *cctx)
cmd = skipwhite(cmd);
trailing_error = *cmd != delimiter && *cmd != NUL;
- instr_count = cctx->ctx_instr.ga_len;
- instr = ALLOC_MULT(isn_T, instr_count + 1);
- if (trailing_error || instr == NULL)
+ if (trailing_error || ga_grow(&cctx->ctx_instr, 1) == FAIL)
{
if (trailing_error)
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
// instructions, then restore the list of instructions before
// adding the ISN_SUBSTITUTE instruction.
- mch_memmove(instr, cctx->ctx_instr.ga_data,
- instr_count * sizeof(isn_T));
+ instr_count = cctx->ctx_instr.ga_len;
+ instr = cctx->ctx_instr.ga_data;
instr[instr_count].isn_type = ISN_FINISH;
cctx->ctx_instr = save_ga;