Mercurial > vim
comparison src/libvterm/src/state.c @ 15249:544490b69e1d v8.1.0633
patch 8.1.0633: crash when out of memory while opening a terminal window
commit https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 24 21:38:45 2018 +0100
patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 24 Dec 2018 21:45:05 +0100 |
parents | 17ade2ec0616 |
children | c1698187c482 |
comparison
equal
deleted
inserted
replaced
15248:1e57afb3e8e9 | 15249:544490b69e1d |
---|---|
51 | 51 |
52 static VTermState *vterm_state_new(VTerm *vt) | 52 static VTermState *vterm_state_new(VTerm *vt) |
53 { | 53 { |
54 VTermState *state = vterm_allocator_malloc(vt, sizeof(VTermState)); | 54 VTermState *state = vterm_allocator_malloc(vt, sizeof(VTermState)); |
55 | 55 |
56 if (state == NULL) | |
57 return NULL; | |
56 state->vt = vt; | 58 state->vt = vt; |
57 | 59 |
58 state->rows = vt->rows; | 60 state->rows = vt->rows; |
59 state->cols = vt->cols; | 61 state->cols = vt->cols; |
60 | 62 |
1691 on_osc, /* osc */ | 1693 on_osc, /* osc */ |
1692 on_dcs, /* dcs */ | 1694 on_dcs, /* dcs */ |
1693 on_resize /* resize */ | 1695 on_resize /* resize */ |
1694 }; | 1696 }; |
1695 | 1697 |
1698 /* | |
1699 * Return the existing state or create a new one. | |
1700 * Returns NULL when out of memory. | |
1701 */ | |
1696 VTermState *vterm_obtain_state(VTerm *vt) | 1702 VTermState *vterm_obtain_state(VTerm *vt) |
1697 { | 1703 { |
1698 VTermState *state; | 1704 VTermState *state; |
1699 if(vt->state) | 1705 if(vt->state) |
1700 return vt->state; | 1706 return vt->state; |
1701 | 1707 |
1702 state = vterm_state_new(vt); | 1708 state = vterm_state_new(vt); |
1709 if (state == NULL) | |
1710 return NULL; | |
1703 vt->state = state; | 1711 vt->state = state; |
1704 | 1712 |
1705 state->combine_chars_size = 16; | 1713 state->combine_chars_size = 16; |
1706 state->combine_chars = vterm_allocator_malloc(state->vt, state->combine_chars_size * sizeof(state->combine_chars[0])); | 1714 state->combine_chars = vterm_allocator_malloc(state->vt, state->combine_chars_size * sizeof(state->combine_chars[0])); |
1707 | 1715 |