]> granicus.if.org Git - vim/commitdiff
patch 8.2.2791: Vim9: memory leak when using \=expr in :substitute v8.2.2791
authorBram Moolenaar <Bram@vim.org>
Tue, 20 Apr 2021 19:49:35 +0000 (21:49 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 20 Apr 2021 19:49:35 +0000 (21:49 +0200)
Problem:    Vim9: memory leak when using \=expr in :substitute.
Solution:   Do not allocate a new instruction list.

src/version.c
src/vim9compile.c

index 539d7d5e28bb6fcfcac96cd538d0e74f4b61c5c5..fa2dfae84dfa1d0301b89a9dcd5ce1f3662597a9 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2791,
 /**/
     2790,
 /**/
index 279a8c3a3e6c75b0045ed7d0fb795826d660177f..ade86aa5c5209f756ecb50e12dfb987d0d069763 100644 (file)
@@ -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;