Skip to content

Commit 31842cd

Browse files
committed
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Problem: Vim9: crash after defining function with invalid return type. Solution: Clear function growarrays. Fix memory leak.
1 parent 44ec21c commit 31842cd

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/testdir/test_vim9_func.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,21 @@ def Test_return_invalid()
254254
defcompile
255255
END
256256
CheckScriptFailure(lines, 'E1010:', 2)
257+
258+
lines =<< trim END
259+
vim9script
260+
def Test(Fun: func(number): number): list<number>
261+
return map([1, 2, 3], (_, i) => Fun(i))
262+
enddef
263+
defcompile
264+
def Inc(nr: number): nr
265+
return nr + 2
266+
enddef
267+
echo Test(Inc)
268+
END
269+
# doing this twice was leaking memory
270+
CheckScriptFailure(lines, 'E1010:')
271+
CheckScriptFailure(lines, 'E1010:')
257272
enddef
258273

259274
func Increment()

src/userfunc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,8 +3955,15 @@ define_function(exarg_T *eap, char_u *name_arg)
39553955
erret:
39563956
ga_clear_strings(&newargs);
39573957
ga_clear_strings(&default_args);
3958+
if (fp != NULL)
3959+
{
3960+
ga_init(&fp->uf_args);
3961+
ga_init(&fp->uf_def_args);
3962+
}
39583963
errret_2:
39593964
ga_clear_strings(&newlines);
3965+
if (fp != NULL)
3966+
VIM_CLEAR(fp->uf_arg_types);
39603967
ret_free:
39613968
ga_clear_strings(&argtypes);
39623969
vim_free(skip_until);

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2505,
753755
/**/
754756
2504,
755757
/**/

0 commit comments

Comments
 (0)