From d3df16e84ed1dde54b0282f69da5100765dfb3f4 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 2 May 2025 10:45:47 +0300 Subject: [PATCH] fix(core): propagate exceptions via `unimport.__exit__` [no changelog] --- core/src/trezor/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 55126e262a..7571702031 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -107,7 +107,10 @@ class unimport: self.mods = None gc.collect() - if __debug__ and exc_type is not SystemExit: + # If an exception is being handled here, `check_free_heap()` will fail + # (since the exception survives `gc.collect()` call above). + # So we prefer to skip the check, in order to preserve the exception. + if __debug__ and exc_type is None: self.free_heap = check_free_heap(self.free_heap)