terminal: Fix use after free

Since close_cb may free the terminal structure, save the "wipe" flag before
calling it.
This commit is contained in:
Thiago de Arruda 2015-08-21 23:53:48 -03:00
parent f9778052af
commit 105a72eabc
2 changed files with 13 additions and 1 deletions

View File

@ -422,8 +422,9 @@ end:
redraw(term->buf != curbuf); redraw(term->buf != curbuf);
ui_busy_stop(); ui_busy_stop();
if (close) { if (close) {
bool wipe = term->buf != NULL;
term->opts.close_cb(term->opts.data); term->opts.close_cb(term->opts.data);
if (term->buf) { if (wipe) {
do_cmdline_cmd("bwipeout!"); do_cmdline_cmd("bwipeout!");
} }
} }

View File

@ -343,6 +343,17 @@ describe('terminal prints more lines than the screen height and exits', function
[Program exited, press any key to close] | [Program exited, press any key to close] |
-- TERMINAL -- | -- TERMINAL -- |
]]) ]])
feed('<cr>')
-- closes the buffer correctly after pressing a key
screen:expect([[
^ |
~ |
~ |
~ |
~ |
~ |
|
]])
end) end)
end) end)