Skip to content

Commit 01c31ea

Browse files
felixdoerredpgeorge
authored andcommitted
extmod/os_dupterm: Handle exception properly when it occurs in parallel.
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 <[email protected]> Signed-off-by: Felix Dörre <[email protected]>
1 parent fb3820e commit 01c31ea

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: extmod/os_dupterm.c

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ void mp_os_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) {
4545
if (exc != MP_OBJ_NULL) {
4646
mp_obj_print_exception(&mp_plat_print, exc);
4747
}
48+
if (term == MP_OBJ_NULL) {
49+
// Dupterm was already closed.
50+
return;
51+
}
4852
nlr_buf_t nlr;
4953
if (nlr_push(&nlr) == 0) {
5054
mp_stream_close(term);

0 commit comments

Comments
 (0)