vim-patch:9.0.0204: indexof() may leak memory

Problem:    indexof() may leak memory.
Solution:   Free allocated values. (Yegappan Lakshmanan, closes vim/vim#10916)

63acae13f5

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq 2023-02-27 00:00:01 +08:00
parent 13da3d469a
commit 1f8cef53de
3 changed files with 12 additions and 1 deletions

View File

@ -3505,6 +3505,7 @@ static varnumber_T indexof_eval_expr(typval_T *expr)
bool error = false;
varnumber_T found = tv_get_bool_chk(&newtv, &error);
tv_clear(&newtv);
return error ? false : found;
}
@ -3566,7 +3567,10 @@ static varnumber_T indexof_list(list_T *l, varnumber_T startidx, typval_T *expr)
set_vim_var_nr(VV_KEY, idx);
tv_copy(TV_LIST_ITEM_TV(item), get_vim_var_tv(VV_VAL));
if (indexof_eval_expr(expr)) {
bool found = indexof_eval_expr(expr);
tv_clear(get_vim_var_tv(VV_VAL));
if (found) {
return idx;
}
}

View File

@ -372,6 +372,7 @@ func Test_indexof()
call assert_equal(-1, indexof(b, {i, v -> v == 0x1}))
call assert_equal(1, indexof(b, "v:val == 0xad"))
call assert_equal(-1, indexof(b, "v:val == 0xff"))
call assert_equal(-1, indexof(b, {_, v -> "v == 0xad"}))
call assert_equal(-1, indexof(0z, "v:val == 0x0"))
call assert_equal(-1, indexof(v:_null_blob, "v:val == 0xde"))

View File

@ -1083,7 +1083,13 @@ func Test_indexof()
call assert_equal(-1, indexof(l, "v:val.n == 10", #{startidx: -4}))
call assert_equal(0, indexof(l, "v:val.n == 10", v:_null_dict))
let s = ["a", "b", "c"]
call assert_equal(2, indexof(s, {_, v -> v == 'c'}))
call assert_equal(-1, indexof(s, {_, v -> v == 'd'}))
call assert_equal(-1, indexof(s, {_, v -> "v == 'd'"}))
call assert_equal(-1, indexof([], {i, v -> v == 'a'}))
call assert_equal(-1, indexof([1, 2, 3], {_, v -> "v == 2"}))
call assert_equal(-1, indexof(v:_null_list, {i, v -> v == 'a'}))
call assert_equal(-1, indexof(l, v:_null_string))
" Nvim doesn't have null functions