Skip to content

Commit a43ebe9

Browse files
committed
patch 8.1.0181: memory leak with trailing characters in skip expression
Problem: Memory leak with trailing characters in skip expression. Solution: Free the return value.
1 parent d6ef5f9 commit a43ebe9

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/eval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
729729
return FAIL;
730730
if (*s != NUL) /* check for trailing chars after expr */
731731
{
732+
clear_tv(rettv);
732733
EMSG2(_(e_invexpr2), s);
733734
return FAIL;
734735
}

src/testdir/test_search.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,16 @@ func Test_searchpair_skip()
324324
bw!
325325
endfunc
326326

327+
func Test_searchpair_leak()
328+
new
329+
call setline(1, 'if one else another endif')
330+
331+
" The error in the skip expression caused memory to leak.
332+
call assert_fails("call searchpair('\\<if\\>', '\\<else\\>', '\\<endif\\>', '', '\"foo\" 2')", 'E15:')
333+
334+
bwipe!
335+
endfunc
336+
327337
func Test_searchc()
328338
" These commands used to cause memory overflow in searchc().
329339
new

src/version.c

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

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
181,
792794
/**/
793795
180,
794796
/**/

0 commit comments

Comments
 (0)