fix: Memory leak of g_tx_hash_ctx on aborted signing flows
handle_first_sign_chunk() allocates the global keccak context g_tx_hash_ctx via APP_MEM_CALLOC and only the success path (finalize_parsing_helper) and a subset of post-init parsing errors (handle_sign:180) release it. Other early-error returns inside handle_first_sign_chunk (init_tx failure, invalid data offset, unsupported tx type, cx_hash_no_throw failure) propagate the SW directly to handle_sign and out to main.c without freeing the allocation. Likewise, reset_app_context() never released the context, so app_quit() and the implicit reset at the top of handle_first_sign_chunk left previous-session allocations dangling. A host repeatedly triggering aborted INS_SIGN first-chunk APDUs could exhaust the device's app heap. Add a NULL-checked APP_MEM_FREE_AND_NULL of g_tx_hash_ctx to reset_app_context(). Errors that bubble out of handle_sign reach main.c with reset=true, which now centrally releases the context. The existing late-error free in handle_sign is kept as defense in depth; the NULL check makes the double path safe. (cherry picked from commit d2829917d2fc9d0e39d760fcb6ef578af673f5c2)
C
Charles-Edouard de la Vergne committed
3b8241c2184835f15b69f9fbb8cf8714d20524b1
Parent: cd8220c
Committed by Alexandre Paillier <alexandre.paillier@ledger.fr>
on 8/25/2026, 3:03:56 PM