comparison src/vim9compile.c @ 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 bfa495227ac6
children b5786b4de9d1
comparison
equal deleted inserted replaced
24501:f9f7dc993602 24502:5baac0b4b41c
8542 if (end[-1] == NUL) 8542 if (end[-1] == NUL)
8543 end[-1] = delimiter; 8543 end[-1] = delimiter;
8544 cmd = skipwhite(cmd); 8544 cmd = skipwhite(cmd);
8545 trailing_error = *cmd != delimiter && *cmd != NUL; 8545 trailing_error = *cmd != delimiter && *cmd != NUL;
8546 8546
8547 instr_count = cctx->ctx_instr.ga_len; 8547 if (trailing_error || ga_grow(&cctx->ctx_instr, 1) == FAIL)
8548 instr = ALLOC_MULT(isn_T, instr_count + 1);
8549 if (trailing_error || instr == NULL)
8550 { 8548 {
8551 if (trailing_error) 8549 if (trailing_error)
8552 semsg(_(e_trailing_arg), cmd); 8550 semsg(_(e_trailing_arg), cmd);
8553 clear_instr_ga(&cctx->ctx_instr); 8551 clear_instr_ga(&cctx->ctx_instr);
8554 cctx->ctx_instr = save_ga; 8552 cctx->ctx_instr = save_ga;
8557 } 8555 }
8558 8556
8559 // Move the generated instructions into the ISN_SUBSTITUTE 8557 // Move the generated instructions into the ISN_SUBSTITUTE
8560 // instructions, then restore the list of instructions before 8558 // instructions, then restore the list of instructions before
8561 // adding the ISN_SUBSTITUTE instruction. 8559 // adding the ISN_SUBSTITUTE instruction.
8562 mch_memmove(instr, cctx->ctx_instr.ga_data, 8560 instr_count = cctx->ctx_instr.ga_len;
8563 instr_count * sizeof(isn_T)); 8561 instr = cctx->ctx_instr.ga_data;
8564 instr[instr_count].isn_type = ISN_FINISH; 8562 instr[instr_count].isn_type = ISN_FINISH;
8565 8563
8566 cctx->ctx_instr = save_ga; 8564 cctx->ctx_instr = save_ga;
8567 if ((isn = generate_instr(cctx, ISN_SUBSTITUTE)) == NULL) 8565 if ((isn = generate_instr(cctx, ISN_SUBSTITUTE)) == NULL)
8568 { 8566 {