patch 8.1.1946: memory error when profiling a function without a script ID
Problem: Memory error when profiling a function without a script ID. Solution: Check for missing script ID. (closes #4877)
This commit is contained in:
@ -690,13 +690,16 @@ func_dump_profile(FILE *fd)
|
|||||||
fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3);
|
fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3);
|
||||||
else
|
else
|
||||||
fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
|
fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
|
||||||
p = home_replace_save(NULL,
|
if (fp->uf_script_ctx.sc_sid > 0)
|
||||||
get_scriptname(fp->uf_script_ctx.sc_sid));
|
|
||||||
if (p != NULL)
|
|
||||||
{
|
{
|
||||||
fprintf(fd, " Defined: %s line %ld\n",
|
p = home_replace_save(NULL,
|
||||||
|
get_scriptname(fp->uf_script_ctx.sc_sid));
|
||||||
|
if (p != NULL)
|
||||||
|
{
|
||||||
|
fprintf(fd, " Defined: %s line %ld\n",
|
||||||
p, (long)fp->uf_script_ctx.sc_lnum);
|
p, (long)fp->uf_script_ctx.sc_lnum);
|
||||||
vim_free(p);
|
vim_free(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (fp->uf_tm_count == 1)
|
if (fp->uf_tm_count == 1)
|
||||||
fprintf(fd, "Called 1 time\n");
|
fprintf(fd, "Called 1 time\n");
|
||||||
|
|||||||
@ -4,6 +4,7 @@ source check.vim
|
|||||||
CheckFeature profile
|
CheckFeature profile
|
||||||
|
|
||||||
source shared.vim
|
source shared.vim
|
||||||
|
source screendump.vim
|
||||||
|
|
||||||
func Test_profile_func()
|
func Test_profile_func()
|
||||||
let lines =<< trim [CODE]
|
let lines =<< trim [CODE]
|
||||||
@ -522,3 +523,29 @@ func Test_profdel_star()
|
|||||||
call delete('Xprofile_file.vim')
|
call delete('Xprofile_file.vim')
|
||||||
call delete('Xprofile_file.log')
|
call delete('Xprofile_file.log')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" When typing the function it won't have a script ID, test that this works.
|
||||||
|
func Test_profile_typed_func()
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
profile start XprofileTypedFunc
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XtestProfile')
|
||||||
|
let buf = RunVimInTerminal('-S XtestProfile', #{})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, ":func DoSomething()\<CR>"
|
||||||
|
\ .. "echo 'hello'\<CR>"
|
||||||
|
\ .. "endfunc\<CR>")
|
||||||
|
call term_sendkeys(buf, ":profile func DoSomething\<CR>")
|
||||||
|
call term_sendkeys(buf, ":call DoSomething()\<CR>")
|
||||||
|
call term_wait(buf, 200)
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
let lines = readfile('XprofileTypedFunc')
|
||||||
|
call assert_equal("FUNCTION DoSomething()", lines[0])
|
||||||
|
call assert_equal("Called 1 time", lines[1])
|
||||||
|
|
||||||
|
" clean up
|
||||||
|
call delete('XprofileTypedFunc')
|
||||||
|
call delete('XtestProfile')
|
||||||
|
endfunc
|
||||||
|
|||||||
@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1946,
|
||||||
/**/
|
/**/
|
||||||
1945,
|
1945,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user