From cefa58fa65c749c3ffe538ea9e2a8e7ec3bb5584 Mon Sep 17 00:00:00 2001 From: Jaroslav Pulchart Date: Fri, 20 Nov 2026 23:58:59 +0100 Subject: [PATCH] lowlevel: do not expunge while the input handler is installed Init adds an input handler whose is_Data is the library base, and Expunge freed the base without removing the handler. After a low-memory flush, for example a program allocating most of the free RAM, the next key press ran LowLevelInputHandler on freed memory, walked whatever was there as ll_KBInterrupts and Cause()d a bogus node, which crashed in SoftIntDispatch. Removing the handler needs a DoIO() to the input task, which an expunge under Forbid() must not do, so Expunge refuses while the handler is installed. Expunge also had no return value, it now returns TRUE after the cleanup. --- workbench/libs/lowlevel/lowlevel.conf | 2 +- workbench/libs/lowlevel/lowlevel_init.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/workbench/libs/lowlevel/lowlevel.conf b/workbench/libs/lowlevel/lowlevel.conf index 66dd50e18e7..6c1941d8efc 100644 --- a/workbench/libs/lowlevel/lowlevel.conf +++ b/workbench/libs/lowlevel/lowlevel.conf @@ -1,7 +1,7 @@ ##begin config basename LowLevel libbasetype struct LowLevelBase -version 40.10 +version 40.11 seglist_field ll_SegList ##end config ##begin cdef diff --git a/workbench/libs/lowlevel/lowlevel_init.c b/workbench/libs/lowlevel/lowlevel_init.c index bc1e30e9d08..73815fbb1cf 100644 --- a/workbench/libs/lowlevel/lowlevel_init.c +++ b/workbench/libs/lowlevel/lowlevel_init.c @@ -234,10 +234,19 @@ static int Init(LIBBASETYPEPTR LowLevelBase) static int Expunge(LIBBASETYPEPTR LowLevelBase) { D(bug("[lowlevel] %s()\n", __func__);) + + /* + * The input handler's is_Data is the base. Removing the handler needs a + * DoIO(), which an expunge under Forbid() must not do, so stay. + */ + if (LowLevelBase->ll_InputHandler) + return FALSE; + LowLevelTimerClose(LowLevelBase); LowLevelInputClose(LowLevelBase); if (LowLevelBase->ll_UtilityBase) CloseLibrary(LowLevelBase->ll_UtilityBase); + return TRUE; } ADD2INITLIB(Init, 0);