Skip to content

Commit c872a1c

Browse files
Fix other memory leaks
1 parent 4fc264c commit c872a1c

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/transaction/pb_node_display_parser.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ bool init_transaction_pairs(transaction_ctx_t *tx_info, size_t count) {
331331
tx_info->pairs_count = 0;
332332
tx_info->pairs =
333333
(nbgl_contentTagValue_t *) app_mem_alloc(count * sizeof(nbgl_contentTagValue_t));
334+
memset(tx_info->pairs, 0, count * sizeof(nbgl_contentTagValue_t));
334335
tx_info->display_items_strings = (char **) app_mem_alloc(count * sizeof(char *));
335336

336337
if (tx_info->pairs == NULL || tx_info->display_items_strings == NULL) {
@@ -809,6 +810,13 @@ int parse_node_for_display(buffer_t *buf) {
809810
idx++;
810811
ctx.tx_info->pairs_count++;
811812

813+
app_mem_free(state->value);
814+
state->value = NULL;
815+
state->value_len = 0;
816+
}
817+
} else {
818+
// Free any allocated value
819+
if (state->value != NULL) {
812820
app_mem_free(state->value);
813821
state->value = NULL;
814822
state->value_len = 0;

src/ui/nbgl_display_transaction.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "menu.h"
3737
#include "utils.h"
3838

39-
static nbgl_contentTagValue_t pairs[1];
4039
static nbgl_contentTagValueList_t pairList;
4140

4241
// called when long press button on 3rd page is long-touched or when reject footer is touched
@@ -65,10 +64,14 @@ int ui_display_transaction_bs_choice(bool is_blind_signed) {
6564
PRINTF("Hash: %.*H\n", sizeof(G_context.tx_info.m_hash), G_context.tx_info.m_hash);
6665
// Setup data to display
6766
size_t hex_hash_length = 2 * G_context.tx_info.m_hash_len + 1;
68-
pairs[0].value = (char *) app_mem_alloc(hex_hash_length);
69-
LEDGER_ASSERT(pairs[0].value != NULL, "Memory full");
70-
pairs[0].item = "Transaction hash";
71-
SNPRINTF((char *) pairs[0].value,
67+
G_context.tx_info.pairs =
68+
(nbgl_contentTagValue_t *) app_mem_alloc(sizeof(nbgl_contentTagValue_t));
69+
LEDGER_ASSERT(G_context.tx_info.pairs != NULL, "Memory full");
70+
memset(G_context.tx_info.pairs, 0, sizeof(nbgl_contentTagValue_t));
71+
G_context.tx_info.pairs[0].item = "Transaction hash";
72+
G_context.tx_info.pairs[0].value = (char *) app_mem_alloc(hex_hash_length);
73+
LEDGER_ASSERT(G_context.tx_info.pairs[0].value != NULL, "Memory full");
74+
SNPRINTF((char *) G_context.tx_info.pairs[0].value,
7275
hex_hash_length,
7376
"%.*H",
7477
G_context.tx_info.m_hash_len,
@@ -77,7 +80,7 @@ int ui_display_transaction_bs_choice(bool is_blind_signed) {
7780
// Setup list
7881
pairList.nbMaxLinesForValue = 0;
7982
pairList.nbPairs = 1;
80-
pairList.pairs = pairs;
83+
pairList.pairs = G_context.tx_info.pairs;
8184

8285
// Start blind-signing review flow
8386
nbgl_useCaseReviewBlindSigning(TYPE_TRANSACTION,

0 commit comments

Comments
 (0)