diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-06-24 06:50:48 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-06-24 07:26:06 +0800 |
commit | affeb5c6ddbda0c34a9513e393d2b05f622e1514 (patch) | |
tree | 7e6e6e9fb52b131b6fee5c412280353cbddae53e /src/nvim/ex_cmds.c | |
parent | 589f418fceadfbbc10a6d1d37dd5d2ed026342b5 (diff) | |
download | rneovim-affeb5c6ddbda0c34a9513e393d2b05f622e1514.tar.gz rneovim-affeb5c6ddbda0c34a9513e393d2b05f622e1514.tar.bz2 rneovim-affeb5c6ddbda0c34a9513e393d2b05f622e1514.zip |
vim-patch:8.2.5146: memory leak when substitute expression nests
Problem: Memory leak when substitute expression nests.
Solution: Use an array of expression results.
https://github.com/vim/vim/commit/44ddf19ec0ff59c969658ec7d9ed42070c59c51b
Cherry-pick a comment change from patch 8.2.5057.
N/A patches for version.c:
vim-patch:8.2.5154: still mentioning version8, some cosmetic issues
Problem: Still mentioning version8, some cosmetic issues.
Solution: Prefer mentioning version9, cosmetic improvements.
https://github.com/vim/vim/commit/abd56da30bae4a5c6c20b9363ccae12f7b126026
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r-- | src/nvim/ex_cmds.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 7f929eec3e..a1f0a123b1 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3468,7 +3468,6 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T static int pre_hl_id = 0; pos_T old_cursor = curwin->w_cursor; int start_nsubs; - int save_ma = 0; bool did_save = false; @@ -4060,7 +4059,8 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // there is a replace pattern. if (!cmdpreview || has_second_delim) { long lnum_start = lnum; // save the start lnum - save_ma = curbuf->b_p_ma; + int save_ma = curbuf->b_p_ma; + int save_sandbox = sandbox; if (subflags.do_count) { // prevent accidentally changing the buffer by a function curbuf->b_p_ma = false; @@ -4072,7 +4072,8 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // Disallow changing text or switching window in an expression. textlock++; - // get length of substitution part + // Get length of substitution part, including the NUL. + // When it fails sublen is zero. sublen = vim_regsub_multi(®match, sub_firstlnum - regmatch.startpos[0].lnum, (char_u *)sub, (char_u *)sub_firstline, 0, @@ -4083,11 +4084,9 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // 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; } |