Skip to content

Commit

Permalink
fix(core): explicitly delete keyboard layout
Browse files Browse the repository at this point in the history
- seems that keyboard LayoutObj was not properly deallocated resulting
in MemoryError. Fix by calling the dunder `del` method explicitly fixes
the issue
- the problem was on Model T (Bolt), but applying it for all layouts to
prevent similar problem
  • Loading branch information
obrusvit committed Jan 27, 2025
1 parent 71306d0 commit 15967a3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions core/.changelog.d/4537.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[T2T1] Fixed a bug resulting in restarting the recovery flow when inputting 33-word mnemonic.
15 changes: 9 additions & 6 deletions core/src/trezor/ui/layouts/bolt/recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ async def request_word(
) -> str:
prompt = TR.recovery__type_word_x_of_y_template.format(word_index + 1, word_count)
can_go_back = word_index > 0

if is_slip39:
keyboard = trezorui_api.request_slip39(
prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back
)

else:
keyboard = trezorui_api.request_bip39(
prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back
)

word: str = await interact(
keyboard,
"mnemonic" if send_button_request else None,
ButtonRequestType.MnemonicInput,
)
try:
word: str = await interact(
keyboard,
"mnemonic" if send_button_request else None,
ButtonRequestType.MnemonicInput,
)
finally:
keyboard.__del__()
return word


Expand Down
15 changes: 8 additions & 7 deletions core/src/trezor/ui/layouts/caesar/recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,25 @@ async def request_word(
prefill_word: str = "",
) -> str:
prompt = TR.recovery__word_x_of_y_template.format(word_index + 1, word_count)

can_go_back = word_index > 0

if is_slip39:
keyboard = trezorui_api.request_slip39(
prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back
)

else:
keyboard = trezorui_api.request_bip39(
prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back
)

word: str = await interact(
keyboard,
"mnemonic" if send_button_request else None,
ButtonRequestType.MnemonicInput,
)
try:
word: str = await interact(
keyboard,
"mnemonic" if send_button_request else None,
ButtonRequestType.MnemonicInput,
)
finally:
keyboard.__del__()
return word


Expand Down
14 changes: 9 additions & 5 deletions core/src/trezor/ui/layouts/delizia/recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async def request_word(
) -> str:
prompt = TR.recovery__word_x_of_y_template.format(word_index + 1, word_count)
can_go_back = word_index > 0

if is_slip39:
keyboard = trezorui_api.request_slip39(
prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back
Expand All @@ -42,11 +43,14 @@ async def request_word(
prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back
)

word: str = await interact(
keyboard,
"mnemonic" if send_button_request else None,
ButtonRequestType.MnemonicInput,
)
try:
word: str = await interact(
keyboard,
"mnemonic" if send_button_request else None,
ButtonRequestType.MnemonicInput,
)
finally:
keyboard.__del__()
return word


Expand Down

0 comments on commit 15967a3

Please sign in to comment.