Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 89ec921

Browse files
author
Wu Yu Wei
authored
Merge pull request #123 from HowJMay/fix_pow_memey_leak
fix(pow): Fix memory leaks in pow.c
2 parents 7dc1e3c + e0b0bc5 commit 89ec921

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

utils/pow.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ flex_trit_t* ta_pow_flex(const flex_trit_t* const trits_in, const uint8_t mwm) {
3939
status_t ta_pow(const bundle_transactions_t* bundle,
4040
const flex_trit_t* const trunk, const flex_trit_t* const branch,
4141
const uint8_t mwm) {
42+
status_t ret = SC_OK;
4243
iota_transaction_t* tx;
4344
flex_trit_t* ctrunk =
4445
(flex_trit_t*)calloc(FLEX_TRIT_SIZE_243, sizeof(flex_trit_t));
4546
size_t cur_idx = 0;
4647

4748
tx = (iota_transaction_t*)utarray_front(bundle);
49+
if (tx == NULL) {
50+
ret = SC_TA_NULL;
51+
goto done;
52+
}
4853
cur_idx = transaction_last_index(tx) + 1;
4954
memcpy(ctrunk, trunk, FLEX_TRIT_SIZE_243);
5055

@@ -60,13 +65,15 @@ status_t ta_pow(const bundle_transactions_t* bundle,
6065

6166
flex_trit_t* tx_trits = transaction_serialize(tx);
6267
if (tx_trits == NULL) {
63-
return SC_CCLIENT_INVALID_FLEX_TRITS;
68+
ret = SC_CCLIENT_INVALID_FLEX_TRITS;
69+
goto done;
6470
}
6571

6672
// get nonce
6773
flex_trit_t* nonce = ta_pow_flex(tx_trits, mwm);
6874
if (nonce == NULL) {
69-
return SC_TA_OOM;
75+
ret = SC_TA_OOM;
76+
goto done;
7077
}
7178
transaction_set_nonce(tx, nonce);
7279

@@ -76,6 +83,7 @@ status_t ta_pow(const bundle_transactions_t* bundle,
7683
free(tx_trits);
7784
} while (cur_idx != 0);
7885

86+
done:
7987
free(ctrunk);
80-
return SC_OK;
88+
return ret;
8189
}

0 commit comments

Comments
 (0)