This patch is causing segfaults for me. I've built with and without it to verify.
I have a timer to check a couple files and update my color scheme when they change. I haven't tried to narrow down any specific lines yet, but when TryTheme actually triggers then vim segfaults immediately. Maybe because of the try/catch?
Here's the code from my vimrc:
function! TryTheme(theme, ...)
let l:background = a:0 ? a:1 : ''
if a:theme == 'solarized'
" force dark bg to prevent double toggle with term scheme
let l:background = 'dark'
endif
if exists('g:colors_name') && g:colors_name == a:theme &&
\ empty(l:background) || &background == l:background
return 1
endif
try
exec 'colorscheme' a:theme
catch /^Vim\%((\a\+)\)\=:E185/
return 0
endtry
if ! empty(l:background)
let &background = l:background
endif
if exists('syntax_on')
syn reset
endif
endfunction
function! LoadTheme()
let l:background_file = expand('~/.vim/background')
let l:theme_file = expand('~/.vim/theme')
let l:background = filereadable(l:background_file) ?
\ readfile(l:background_file)[0] : &background
let l:theme = filereadable(l:theme_file) ?
\ readfile(l:theme_file)[0] : 'default'
if l:background == &background &&
\ exists('g:colors_name') && l:theme == g:colors_name
return 0
endif
" echom l:theme . " " . l:background
call TryTheme(l:theme, l:background)
endfunction
call LoadTheme()
if has("timers")
function! LoadThemeTimer(timer)
call LoadTheme()
endfunction
let theme_timer = timer_start(1000, 'LoadThemeTimer', {'repeat': -1})
endif
Aron Griffis wrote:
> On Saturday, July 8, 2017 at 4:38:36 PM UTC-4, Bram Moolenaar wrote:
> > Patch 8.0.0702
> > Problem: An error in a timer can make Vim unusable.
> > Solution: Don't set the error flag or exception from a timer. Stop a timer
> > if it causes an error 3 out of 3 times. Discard an exception
> > caused inside a timer.
> > Files: src/ex_cmds2.c, src/structs.h, src/testdir/test_timers.vim,
> > runtime/doc/eval.txt
>
> This patch is causing segfaults for me. I've built with and without it to verify.
>
> I have a timer to check a couple files and update my color scheme when they change. I haven't tried to narrow down any specific lines yet, but when TryTheme actually triggers then vim segfaults immediately. Maybe because of the try/catch?
>
> Here's the code from my vimrc:
[..]
I haven't managed to reproduce it. Can you run Vim in a debugger and
see the call stack?
On Sun, Jul 9, 2017 at 1:19 PM, Bram Moolenaar <Br...@moolenaar.net> wrote:
Aron Griffis wrote:
> On Saturday, July 8, 2017 at 4:38:36 PM UTC-4, Bram Moolenaar wrote:
> > Patch 8.0.0702
> > Problem: An error in a timer can make Vim unusable.
> > Solution: Don't set the error flag or exception from a timer. Stop a timer
> > if it causes an error 3 out of 3 times. Discard an exception
> > caused inside a timer.
> > Files: src/ex_cmds2.c, src/structs.h, src/testdir/test_timers.vim,
> > runtime/doc/eval.txt
>
> This patch is causing segfaults for me. I've built with and without it to verify.
>
> I have a timer to check a couple files and update my color scheme when they change. I haven't tried to narrow down any specific lines yet, but when TryTheme actually triggers then vim segfaults immediately. Maybe because of the try/catch?
>
> Here's the code from my vimrc:
[..]
I haven't managed to reproduce it. Can you run Vim in a debugger and
see the call stack?
[..]
Full disclosure: My build includes a few extra patches from the Fedora RPM, but since Christian got a similar backtrace, I don't think those patches are related.
In fact, I just rebuilt from pristine 702 source to make sure:$ CFLAGS=-ggdb ./configure --enable-gui=no --without-x$ make$ cd src$ gdb ./vim(gdb) run(change the content of .vim/background and .vim/scheme, cause segfault)
Can you reproduce the crash with valgrind? It may give
useful information. Just run vim as:
$ valgrind --num-callers=50 --track-origins=yes ./vim 2> vg.log
and vg.log will contain useful info if you manage to reproduce the bug.
test.vim
```
try
throw 'excp'
catch
"
endtry
fu! TimerFunc(...)
echoerr 'oops'
endfu
call timer_start(1, 'TimerFunc')
```
vim -Nu test.vim
cause:
At finishing above try-catch-endtry, "current_exception" has directed a
dangling pointer (already freed).
Therefore, after emsg() is called in timer-callback, "current_exception" is
double-freed.
(at discard_current_exception() in check_due_timer(), ex_cmds2.c:L1239)
details:
* ex_throw() -> throw_exception() sets current_exception (ex_eval.c:L575)
* ex_catch() sets did_throw to FALSE
* ex_endtry() -> cleanup_conditionals() -> finish_exception() -> discard_exception() frees cstack->cs_exception[idx] (== current_exception)
* but, did_throw is already FALSE, discard_current_exception() is not called from anyone (except check_due_timer()).
* thus current_exception is not cleanup and keeps freed pointer.
Ozaki Kiichi