Skip to content

Commit 8e9be20

Browse files
committed
patch 8.2.1638: leaking memory when popup filter function can't be called
Problem: Leaking memory when popup filter function can't be called. Solution: Don't return too soon.
1 parent c3516f7 commit 8e9be20

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/popupwin.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,31 +3155,33 @@ invoke_popup_filter(win_T *wp, int c)
31553155
if (call_callback(&wp->w_filter_cb, -1, &rettv, 2, argv) == FAIL)
31563156
{
31573157
// Cannot call the function, close the popup to avoid that the filter
3158-
// eats keys and the user can't get out.
3158+
// eats keys and the user is stuck. Might as well eat the key.
31593159
popup_close_with_retval(wp, -1);
3160-
return 1;
3161-
}
3162-
3163-
if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
3164-
popup_highlight_curline(wp);
3165-
3166-
// If an error was given always return FALSE, so that keys are not
3167-
// consumed and the user can type something.
3168-
// If we get three errors in a row then close the popup. Decrement the
3169-
// error count by 1/10 if there are no errors, thus allowing up to 1 in
3170-
// 10 calls to cause an error.
3171-
if (win_valid_popup(wp) && called_emsg > prev_called_emsg)
3172-
{
3173-
wp->w_filter_errors += 10;
3174-
if (wp->w_filter_errors >= 30)
3175-
popup_close_with_retval(wp, -1);
3176-
res = FALSE;
3160+
res = TRUE;
31773161
}
31783162
else
31793163
{
3180-
if (win_valid_popup(wp) && wp->w_filter_errors > 0)
3181-
--wp->w_filter_errors;
3182-
res = tv_get_bool(&rettv);
3164+
if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
3165+
popup_highlight_curline(wp);
3166+
3167+
// If an error was given always return FALSE, so that keys are not
3168+
// consumed and the user can type something.
3169+
// If we get three errors in a row then close the popup. Decrement the
3170+
// error count by 1/10 if there are no errors, thus allowing up to 1 in
3171+
// 10 calls to cause an error.
3172+
if (win_valid_popup(wp) && called_emsg > prev_called_emsg)
3173+
{
3174+
wp->w_filter_errors += 10;
3175+
if (wp->w_filter_errors >= 30)
3176+
popup_close_with_retval(wp, -1);
3177+
res = FALSE;
3178+
}
3179+
else
3180+
{
3181+
if (win_valid_popup(wp) && wp->w_filter_errors > 0)
3182+
--wp->w_filter_errors;
3183+
res = tv_get_bool(&rettv);
3184+
}
31833185
}
31843186

31853187
vim_free(argv[1].vval.v_string);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1638,
757759
/**/
758760
1637,
759761
/**/

0 commit comments

Comments
 (0)