diff --git a/modules/net/dap_chain_ledger.c b/modules/net/dap_chain_ledger.c index a7f9ec38c066ce44d7f73e931cd74c585505f9de..ff1c0b6459a8ac0258f3d080bb05e76da98b6bfd 100644 --- a/modules/net/dap_chain_ledger.c +++ b/modules/net/dap_chain_ledger.c @@ -2812,13 +2812,17 @@ int s_emission_add_check(dap_ledger_t *a_ledger, byte_t *a_token_emission, size_ dap_sign_t **l_signs = dap_sign_get_unique_signs(l_emission->tsd_n_signs + l_emission->data.type_auth.tsd_total_size, l_emission->data.type_auth.tsd_n_signs_size, &l_signs_unique); if (l_signs_unique < l_token_item->auth_signs_valid) { + + DAP_DELETE(l_signs); + if (!s_check_hal(a_ledger, a_emission_hash)) { - DAP_DEL_Z(l_signs); + log_it(L_WARNING, "The number of unique token signs %zu is less than total token signs set to %zu", l_signs_unique, l_token_item->auth_signs_total); DAP_DELETE(l_emission); return DAP_LEDGER_CHECK_NOT_ENOUGH_VALID_SIGNS; } + goto ret_success; } size_t l_sign_auth_count = l_emission->data.type_auth.signs_count; @@ -2869,6 +2873,7 @@ ret_success: *a_emission = l_emission; else DAP_DELETE(l_emission); + return DAP_LEDGER_CHECK_OK; } diff --git a/modules/type/blocks/dap_chain_block_cache.c b/modules/type/blocks/dap_chain_block_cache.c index b3e9a031664af71565adcd7246bd017fe101cf05..b329e6d7766029c87081174aaf429986602fc690 100644 --- a/modules/type/blocks/dap_chain_block_cache.c +++ b/modules/type/blocks/dap_chain_block_cache.c @@ -113,7 +113,8 @@ int dap_chain_block_cache_update(dap_chain_block_cache_t *a_block_cache, dap_has a_block_cache->block_hash = *a_block_hash; else dap_hash_fast(a_block_cache->block, a_block_cache->block_size, &a_block_cache->block_hash); - a_block_cache->block_hash_str = dap_hash_fast_to_str_new(&a_block_cache->block_hash); + + dap_hash_fast_to_str(&a_block_cache->block_hash, &a_block_cache->block_hash_str, DAP_CHAIN_HASH_FAST_STR_SIZE); if (dap_chain_block_meta_extract(a_block_cache->block, a_block_cache->block_size, &a_block_cache->prev_hash, @@ -147,7 +148,6 @@ int dap_chain_block_cache_update(dap_chain_block_cache_t *a_block_cache, dap_has */ void dap_chain_block_cache_delete(dap_chain_block_cache_t * a_block_cache) { - DAP_DEL_Z(a_block_cache->block_hash_str); DAP_DEL_Z(a_block_cache->datum); DAP_DEL_Z(a_block_cache->datum_hash); DAP_DEL_Z(a_block_cache->links_hash); diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index 615ef99af611672a064d50647d3a98acdffe77ef..ea48d44a6ae9abfa95c2a993ff7cf133baf866c2 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -1711,6 +1711,7 @@ static dap_chain_atom_verify_res_t s_callback_atom_add(dap_chain_t * a_chain, da return ATOM_FORK; } } + } else { HASH_ADD(hh, PVT(l_blocks)->blocks, block_hash, sizeof(l_block_cache->block_hash), l_block_cache); ++PVT(l_blocks)->blocks_count; @@ -1721,6 +1722,8 @@ static dap_chain_atom_verify_res_t s_callback_atom_add(dap_chain_t * a_chain, da pthread_rwlock_unlock(&PVT(l_blocks)->rwlock); return ret; } + + DAP_DELETE(l_block_cache); pthread_rwlock_unlock(&PVT(l_blocks)->rwlock); debug_if(s_debug_more, L_DEBUG, "Verified atom %p: REJECTED", a_atom); return ATOM_REJECT; @@ -1780,6 +1783,8 @@ static dap_chain_atom_verify_res_t s_callback_atom_add(dap_chain_t * a_chain, da debug_if(s_debug_more, L_DEBUG, "Fork is made successfuly."); return ATOM_FORK; } + + DAP_DELETE(l_block_cache); pthread_rwlock_unlock(& PVT(l_blocks)->rwlock); return ATOM_REJECT; } diff --git a/modules/type/blocks/include/dap_chain_block_cache.h b/modules/type/blocks/include/dap_chain_block_cache.h index 0eda48a142473214854d4f6eff1e8b816747371e..2a622f0a0a1d5c431a46c8006fec85e6127e40e1 100644 --- a/modules/type/blocks/include/dap_chain_block_cache.h +++ b/modules/type/blocks/include/dap_chain_block_cache.h @@ -31,7 +31,7 @@ typedef struct dap_chain_cs_blocks dap_chain_cs_blocks_t; typedef struct dap_chain_block_cache { // Block's general non-nested attributes dap_chain_hash_fast_t block_hash; - char* block_hash_str; + char block_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; size_t block_size; uint64_t block_number;