summaryrefslogtreecommitdiffstats
path: root/src/ex_cmds.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-06-21 22:15:25 +0100
committerBram Moolenaar <Bram@vim.org>2022-06-21 22:15:25 +0100
commit44ddf19ec0ff59c969658ec7d9ed42070c59c51b (patch)
tree3bb890d6ead77f4a66e3c64a5e7ed0a21b6dd26f /src/ex_cmds.c
parentcf801d4b95180ddaee1bf633ef482232625dd80b (diff)
patch 8.2.5146: memory leak when substitute expression nestsv8.2.5146
Problem: Memory leak when substitute expression nests. Solution: Use an array of expression results.
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r--src/ex_cmds.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 34a740da24..eb3016fe57 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3701,6 +3701,7 @@ ex_substitute(exarg_T *eap)
int start_nsubs;
#ifdef FEAT_EVAL
int save_ma = 0;
+ int save_sandbox = 0;
#endif
cmd = eap->arg;
@@ -4403,6 +4404,7 @@ ex_substitute(exarg_T *eap)
*/
#ifdef FEAT_EVAL
save_ma = curbuf->b_p_ma;
+ save_sandbox = sandbox;
if (subflags.do_count)
{
// prevent accidentally changing the buffer by a function
@@ -4416,7 +4418,8 @@ ex_substitute(exarg_T *eap)
// Disallow changing text or switching window in an expression.
++textlock;
#endif
- // get length of substitution part
+ // Get length of substitution part, including the NUL.
+ // When it fails sublen is zero.
sublen = vim_regsub_multi(&regmatch,
sub_firstlnum - regmatch.startpos[0].lnum,
sub, sub_firstline, 0,
@@ -4429,11 +4432,10 @@ ex_substitute(exarg_T *eap)
// the replacement.
// Don't keep flags set by a recursive call.
subflags = subflags_save;
- if (aborting() || subflags.do_count)
+ if (sublen == 0 || aborting() || subflags.do_count)
{
curbuf->b_p_ma = save_ma;
- if (sandbox > 0)
- sandbox--;
+ sandbox = save_sandbox;
goto skip;
}
#endif