diff 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
line wrap: on
line diff
--- a/src/libvterm/src/state.c
+++ b/src/libvterm/src/state.c
@@ -53,6 +53,8 @@ static VTermState *vterm_state_new(VTerm
 {
   VTermState *state = vterm_allocator_malloc(vt, sizeof(VTermState));
 
+  if (state == NULL)
+    return NULL;
   state->vt = vt;
 
   state->rows = vt->rows;
@@ -1693,6 +1695,10 @@ static const VTermParserCallbacks parser
   on_resize /* resize */
 };
 
+/*
+ * Return the existing state or create a new one.
+ * Returns NULL when out of memory.
+ */
 VTermState *vterm_obtain_state(VTerm *vt)
 {
   VTermState *state;
@@ -1700,6 +1706,8 @@ VTermState *vterm_obtain_state(VTerm *vt
     return vt->state;
 
   state = vterm_state_new(vt);
+  if (state == NULL)
+    return NULL;
   vt->state = state;
 
   state->combine_chars_size = 16;