From 01c31ea804c7e2a034e1249b43c30673b4382116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Sat, 24 Feb 2024 23:44:47 +0000 Subject: [PATCH] extmod/os_dupterm: Handle exception properly when it occurs in parallel. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an exception is handled and the stream is closed, but while this happens, another exception occurs or dupterm is deactivated for another reason, the initial deactivation crashes, because its dupterm is removed. Co-authored-by: Damien George Signed-off-by: Felix Dörre --- extmod/os_dupterm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extmod/os_dupterm.c b/extmod/os_dupterm.c index 156766a43c..399f2237fb 100644 --- a/extmod/os_dupterm.c +++ b/extmod/os_dupterm.c @@ -45,6 +45,10 @@ void mp_os_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) { if (exc != MP_OBJ_NULL) { mp_obj_print_exception(&mp_plat_print, exc); } + if (term == MP_OBJ_NULL) { + // Dupterm was already closed. + return; + } nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_stream_close(term);