changeset 24502:5baac0b4b41c v8.2.2791

patch 8.2.2791: Vim9: memory leak when using =expr in :substitute Commit: https://github.com/vim/vim/commit/5c787fb7928c4cc1e7d6eec0be1bbd63d903cc8d Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 20 21:49:35 2021 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Tue, 20 Apr 2021 22:00:04 +0200
parents f9f7dc993602
children 5e394def267d
files src/version.c src/vim9compile.c
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2791,
+/**/
     2790,
 /**/
     2789,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8544,9 +8544,7 @@ compile_substitute(char_u *arg, exarg_T 
 	    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 
 	    // 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;