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

Commit b40068d

Browse files
author
Yu Wei Wu
committed
fix: potential memory leak in ta_find_tx_by_tag
There's a potential memory leak if ta_find_transactions_obj_by_tag get more than one trasaction with given tag. Move the scope of ta_get_transaction_object_res_t can insure the memories are actually free.
1 parent 3d59964 commit b40068d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

accelerator/common_core.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,7 @@ int ta_find_transactions_obj_by_tag(const iota_client_service_t* const service,
386386
flex_trit_t* hash_trits = NULL;
387387

388388
ta_find_transactions_res_t* hash_res = ta_find_transactions_res_new();
389-
ta_get_transaction_object_res_t* obj_res =
390-
ta_get_transaction_object_res_new();
391-
if (hash_res == NULL || obj_res == NULL) {
389+
if (hash_res == NULL) {
392390
ret = -1;
393391
goto done;
394392
}
@@ -402,6 +400,12 @@ int ta_find_transactions_obj_by_tag(const iota_client_service_t* const service,
402400
// get transaction obj
403401
for (hash_trits = hash243_queue_peek(hash_res->hashes); hash_trits != NULL;
404402
hash_trits = hash243_queue_peek(hash_res->hashes)) {
403+
ta_get_transaction_object_res_t* obj_res =
404+
ta_get_transaction_object_res_new();
405+
if (obj_res == NULL) {
406+
ret = -1;
407+
goto done;
408+
}
405409
flex_trits_to_trytes((tryte_t*)hash_trytes, NUM_TRYTES_HASH, hash_trits,
406410
NUM_TRITS_HASH, NUM_TRITS_HASH);
407411
hash243_queue_pop(&hash_res->hashes);
@@ -411,10 +415,10 @@ int ta_find_transactions_obj_by_tag(const iota_client_service_t* const service,
411415
break;
412416
}
413417
utarray_push_back(res->txn_obj, obj_res->txn);
418+
ta_get_transaction_object_res_free(&obj_res);
414419
}
415420

416421
done:
417422
ta_find_transactions_res_free(&hash_res);
418-
ta_get_transaction_object_res_free(&obj_res);
419423
return ret;
420424
}

0 commit comments

Comments
 (0)