1
0
forked from aniani/vim

patch 9.0.0047: using freed memory with recursive substitute

Problem:    Using freed memory with recursive substitute.
Solution:   Always make a copy for reg_prev_sub.
This commit is contained in:
Bram Moolenaar
2022-07-07 22:20:31 +01:00
parent baefde1455
commit 32acf1f1a7
4 changed files with 27 additions and 5 deletions

View File

@@ -1766,11 +1766,11 @@ regtilde(char_u *source, int magic)
}
}
// Store a copy of newsub in reg_prev_sub. It is always allocated,
// because recursive calls may make the returned string invalid.
vim_free(reg_prev_sub);
if (newsub != source) // newsub was allocated, just keep it
reg_prev_sub = newsub;
else // no ~ found, need to save newsub
reg_prev_sub = vim_strsave(newsub);
reg_prev_sub = vim_strsave(newsub);
return newsub;
}