mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-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 vim/vim#4877)
163588005d
This commit is contained in:
parent
9db60b06a1
commit
d3f1eb3024
@ -22147,16 +22147,18 @@ void func_dump_profile(FILE *fd)
|
|||||||
} else {
|
} else {
|
||||||
fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
|
fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
|
||||||
}
|
}
|
||||||
bool should_free;
|
if (fp->uf_script_ctx.sc_sid != 0) {
|
||||||
const LastSet last_set = (LastSet){
|
bool should_free;
|
||||||
.script_ctx = fp->uf_script_ctx,
|
const LastSet last_set = (LastSet){
|
||||||
.channel_id = 0,
|
.script_ctx = fp->uf_script_ctx,
|
||||||
};
|
.channel_id = 0,
|
||||||
char_u *p = get_scriptname(last_set, &should_free);
|
};
|
||||||
fprintf(fd, " Defined: %s line %" PRIdLINENR "\n",
|
char_u *p = get_scriptname(last_set, &should_free);
|
||||||
p, fp->uf_script_ctx.sc_lnum);
|
fprintf(fd, " Defined: %s line %" PRIdLINENR "\n",
|
||||||
if (should_free) {
|
p, fp->uf_script_ctx.sc_lnum);
|
||||||
xfree(p);
|
if (should_free) {
|
||||||
|
xfree(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");
|
||||||
|
0
src/nvim/testdir/screendump.vim
Normal file
0
src/nvim/testdir/screendump.vim
Normal file
@ -216,7 +216,7 @@ func Test_set_completion()
|
|||||||
|
|
||||||
" Expand files and directories.
|
" Expand files and directories.
|
||||||
call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
|
call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
|
||||||
call assert_match('./samples/ ./sautest/ ./setup.vim ./shared.vim', @:)
|
call assert_match('./samples/ ./sautest/ ./screendump.vim ./setup.vim ./shared.vim', @:)
|
||||||
|
|
||||||
call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
|
call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
|
||||||
call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
|
call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
|
||||||
|
@ -3,6 +3,8 @@ if !has('profile')
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
source screendump.vim
|
||||||
|
|
||||||
func Test_profile_func()
|
func Test_profile_func()
|
||||||
let lines = [
|
let lines = [
|
||||||
\ 'profile start Xprofile_func.log',
|
\ 'profile start Xprofile_func.log',
|
||||||
@ -518,3 +520,31 @@ 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()
|
||||||
|
if !CanRunVimInTerminal()
|
||||||
|
throw 'Skipped: cannot run Vim in a terminal window'
|
||||||
|
endif
|
||||||
|
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user