jcs
/subtext
/amendments
/337
console: Handle malloc failure
jcs made amendment 337 about 1 year ago
--- console.c Sun Feb 5 11:13:11 2023
+++ console.c Wed Mar 1 22:48:21 2023
@@ -68,8 +68,10 @@ console_init(void)
Rect bounds;
short width, height;
- console = xmalloczero(sizeof(struct console), "console_init");
-
+ console = xmalloczero(sizeof(struct console));
+ if (console == NULL)
+ return NULL;
+
console->session = session_create("console", "console",
&console_node_funcs);
if (console->session == NULL) {
@@ -99,17 +101,27 @@ console_init(void)
console->win = NewWindow(0L, &bounds, title, false, noGrowDocProc,
(WindowPtr)-1L, true, 0);
- if (!console->win)
- panic("Can't create window");
+ if (!console->win) {
+ warn("Can't create window");
+ xfree(&console);
+ return NULL;
+ }
- focusable = xmalloczero(sizeof(struct focusable), "console focusable");
+ focusable = xmalloczero(sizeof(struct focusable));
+ if (focusable == NULL) {
+ xfree(&console);
+ return NULL;
+ }
focusable->win = console->win;
focusable->cookie = console;
focusable->update = console_update;
focusable->key_down = console_key_down;
focusable->close = console_close;
console->focusable = focusable;
- add_focusable(focusable);
+ if (!add_focusable(focusable)) {
+ xfree(&console);
+ return NULL;
+ }
console->session->cookie = (void *)console;
console->session->vt100 = 1;