diff --git a/src/abi.c b/src/abi.c index a030dba..9ba0a1f 100644 --- a/src/abi.c +++ b/src/abi.c @@ -302,6 +302,7 @@ int eth_abi_address(struct eth_abi *abi, char **addr) { memcpy(&(cframebuf->buf[cframebuf->offset + 12]), tmp, 20); cframebuf->offset += ETH_ABI_WORD_SIZE; cframebuf->len += ETH_ABI_WORD_SIZE; + free(tmp); return 1; } @@ -326,8 +327,7 @@ int eth_abi_call(struct eth_abi *abi, char **fn, int *len) { cframebuf = abi->cframe->buf; if (abi->m == ETH_ABI_ENCODE) { - if (len == NULL) - fnlen = strlen(*fn); + fnlen = len ? *len : strlen(*fn); if (eth_keccak256(keccak, (uint8_t*)*fn, fnlen) < 0) return -1; @@ -775,6 +775,11 @@ int eth_abi_from_hex(struct eth_abi *abi, char *hex, int len) { if (ethc_abi_frame_init(&nframe) < 0) return -1; + if (nframe->buf->buf != NULL) { + free(nframe->buf->buf); + nframe->buf->buf = NULL; + } + if ((len = eth_hex_to_bytes(&(nframe->buf->buf), hex, len)) < 0) return -1; diff --git a/src/rlp.c b/src/rlp.c index 05aec13..81d1134 100644 --- a/src/rlp.c +++ b/src/rlp.c @@ -563,11 +563,14 @@ int eth_rlp_from_hex(struct eth_rlp *dest, char *hex, int len) { if ((sbuf = eth_hex_to_bytes(&buf, hex, len)) <= 0) return -1; - if (eth_rlp_frame_init(&nframe, buf, sbuf) <= 0) + if (eth_rlp_frame_init(&nframe, buf, sbuf) <= 0) { + free(buf); return -1; + } dest->cframe = nframe; dest->m = ETH_RLP_DECODE; + free(buf); return 1; } @@ -579,5 +582,6 @@ int eth_rlp_free(struct eth_rlp *dest) { cframe = dest->cframe; free(cframe->buf); + free(cframe); return 1; } diff --git a/test/test-eth-abi.c b/test/test-eth-abi.c index 7ebfd5d..a12a25e 100644 --- a/test/test-eth-abi.c +++ b/test/test-eth-abi.c @@ -256,6 +256,7 @@ void test_eth_abi_mpint(void) { ok(eth_abi_mpint(&abi0, mpz1) == 1); ok(eth_abi_mpint(&abi0, mpz2) == 1); ok(eth_abi_to_hex(&abi0, &hex, &hexlen) == 1); + ok(eth_abi_free(&abi0) == 1); is(hex, "00000000000000000000000000000000000000000000000000000000000000ff" "0000000000000000000000000000000000000000000000000000000000000fff" @@ -268,6 +269,7 @@ void test_eth_abi_mpint(void) { mpz_init_set_str(mpz0, "0x0000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0); mpz_init(mpz1); ok(eth_abi_mpint(&abi1, mpz1) == 1); + ok(eth_abi_free(&abi1) == 1); ok(mpz_cmp(mpz0, mpz1) == 0); mpz_clears(mpz0, mpz1, NULL); } @@ -336,7 +338,7 @@ void test_eth_abi_bytes32() { ok(eth_abi_from_hex(&abi1, "f507a54fef38fbd2718fff5f6b54a65d57b079df170b0cd7985d9ce699c031c3", -1) == 1); ok(eth_abi_bytes32(&abi1, b1) == 1); - ok(eth_abi_free(&abi0) == 1); + ok(eth_abi_free(&abi1) == 1); cmp_mem(b1, b0, 32); } diff --git a/test/test-eth-bloom.c b/test/test-eth-bloom.c index c7bdd18..bba7942 100644 --- a/test/test-eth-bloom.c +++ b/test/test-eth-bloom.c @@ -35,6 +35,7 @@ void test_eth_bloom_or(void) { eth_bloom_from_bytes(&bloom1, address, 20); eth_bloom_from_bytes(&bloom2, topic, 32); + eth_bloom_init(&bloom3); eth_bloom_or(&bloom3, &bloom1); eth_bloom_or(&bloom3, &bloom2); diff --git a/test/test-eth-rlp.c b/test/test-eth-rlp.c index 139fc02..0f8b752 100644 --- a/test/test-eth-rlp.c +++ b/test/test-eth-rlp.c @@ -246,6 +246,7 @@ void test_eth_rlp_to_bytes(void) { ok(eth_rlp_free(&rlp0) == 1); cmp_mem(bout, bytes, boutlen); ok(boutlen == 3); + free(bout); } void test_eth_rlp_decode_eip1559_tx(void) { @@ -292,6 +293,7 @@ void test_eth_rlp_decode_eip1559_tx(void) { ok(eth_rlp_hex(&rlp, &r, NULL)); ok(eth_rlp_hex(&rlp, &s, NULL)); ok(eth_rlp_array_end(&rlp)); + ok(eth_rlp_free(&rlp) == 1); // check is(chain_id_hex, "aa36a7"); @@ -308,4 +310,13 @@ void test_eth_rlp_decode_eip1559_tx(void) { ok(v == 1); is(r, "99c06b4f79b805ae7be2dcd21191e470362c9d66b7cfea90b185015893a1477e"); is(s, "3c16ce20c94c5ee0598154007a67fae010769fe3db29a1e40ac9532a91835a0c"); + + free(chain_id_hex); + free(max_priority_fee_per_gas); + free(max_fee_per_gas); + free(gas_limit); + free(to_addr); + free(abi_hex); + free(r); + free(s); }