patch 8.2.0041: leaking memory when selecting spell suggestion
Problem: Leaking memory when selecting spell suggestion.
Solution: Free previous value at the right time.
diff --git a/src/spellsuggest.c b/src/spellsuggest.c
index adf090b..fdd549e 100644
--- a/src/spellsuggest.c
+++ b/src/spellsuggest.c
@@ -540,14 +540,10 @@
else if (count > 0)
{
if (count > sug.su_ga.ga_len)
- smsg(_("Sorry, only %ld suggestions"),
- (long)sug.su_ga.ga_len);
+ smsg(_("Sorry, only %ld suggestions"), (long)sug.su_ga.ga_len);
}
else
{
- VIM_CLEAR(repl_from);
- VIM_CLEAR(repl_to);
-
#ifdef FEAT_RIGHTLEFT
// When 'rightleft' is set the list is drawn right-left.
cmdmsg_rl = curwin->w_p_rl;
@@ -641,6 +637,9 @@
if (selected > 0 && selected <= sug.su_ga.ga_len && u_save_cursor() == OK)
{
// Save the from and to text for :spellrepall.
+ VIM_CLEAR(repl_from);
+ VIM_CLEAR(repl_to);
+
stp = &SUG(sug.su_ga, selected - 1);
if (sug.su_badlen > stp->st_orglen)
{