diff --git a/modules/chain/dap_chain_ledger.c b/modules/chain/dap_chain_ledger.c index db96847502041c7706e1ca70c2ca1b64dc67b860..b03f6910e1c20ac097b90d2ec1c561db14d5cdb4 100644 --- a/modules/chain/dap_chain_ledger.c +++ b/modules/chain/dap_chain_ledger.c @@ -1700,7 +1700,6 @@ static void s_threshold_txs_proc( dap_ledger_t *a_ledger) if (l_res != DAP_CHAIN_CS_VERIFY_CODE_TX_NO_EMISSION && l_res != DAP_CHAIN_CS_VERIFY_CODE_TX_NO_PREVIOUS) { HASH_DEL(l_ledger_pvt->threshold_txs, l_tx_item); - if (l_res != 1) DAP_DELETE(l_tx_item->tx); DAP_DELETE(l_tx_item); l_success = true; @@ -2270,8 +2269,12 @@ static inline int s_token_emission_add(dap_ledger_t *a_ledger, byte_t *a_token_e || (l_token_item->type == DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE) || (l_token_item->type == DAP_CHAIN_DATUM_TOKEN_TYPE_NATIVE_DECL) || (l_token_item->type == DAP_CHAIN_DATUM_TOKEN_TYPE_NATIVE_UPDATE)) { - if (!s_chain_ledger_token_tsd_check(l_token_item, (dap_chain_datum_token_emission_t *)a_token_emission)) - return -114; + if (!s_chain_ledger_token_tsd_check(l_token_item, (dap_chain_datum_token_emission_t *)a_token_emission)) { + DAP_DELETE(l_token_emission_item->datum_token_emission); + DAP_DELETE(l_token_emission_item); + DAP_DELETE(l_hash_str); + return -114; + } } //Update value in ledger memory object if (!IS_ZERO_256(l_token_item->total_supply)) { @@ -2288,6 +2291,9 @@ static inline int s_token_emission_add(dap_ledger_t *a_ledger, byte_t *a_token_e l_balance, l_value); DAP_DELETE(l_balance); DAP_DELETE(l_value); + DAP_DELETE(l_token_emission_item->datum_token_emission); + DAP_DELETE(l_token_emission_item); + DAP_DELETE(l_hash_str); return -4; } if (PVT(a_ledger)->cached) @@ -2327,6 +2333,7 @@ static inline int s_token_emission_add(dap_ledger_t *a_ledger, byte_t *a_token_e DAP_DELETE(l_token_emission_address_str); } } else { + DAP_DELETE(l_token_emission_item->datum_token_emission); DAP_DELETE(l_token_emission_item); if(s_debug_more) log_it(L_WARNING,"threshold for emissions is overfulled (%zu max), dropping down new data, added nothing", @@ -2336,7 +2343,7 @@ static inline int s_token_emission_add(dap_ledger_t *a_ledger, byte_t *a_token_e } else { if (l_token_item) { if(s_debug_more) { - if ( ((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.version == 1 ) { // && ((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.type_256 ) // 256 + if ( ((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.version == 2 ) { char *l_balance = dap_chain_balance_print(((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.value_256); log_it(L_ERROR, "Duplicate token emission datum of %s %s ( %s )", l_balance, c_token_ticker, l_hash_str); DAP_DELETE(l_balance); diff --git a/modules/channel/chain-net/dap_stream_ch_chain_net.c b/modules/channel/chain-net/dap_stream_ch_chain_net.c index c30be87149616f7766a33855c02ceac8f7805b7a..a2994fe2d2ab42b5338d62105d1a70d4aed69755 100644 --- a/modules/channel/chain-net/dap_stream_ch_chain_net.c +++ b/modules/channel/chain-net/dap_stream_ch_chain_net.c @@ -170,7 +170,6 @@ void s_stream_ch_new(dap_stream_ch_t* a_ch, void* a_arg) void s_stream_ch_delete(dap_stream_ch_t* a_ch, void* a_arg) { (void) a_arg; - //printf("* del session=%d\n", a_ch->stream->session->id); dap_stream_ch_chain_net_t * l_ch_chain_net = DAP_STREAM_CH_CHAIN_NET(a_ch); if(l_ch_chain_net) { pthread_mutex_lock(&l_ch_chain_net->mutex); diff --git a/modules/channel/chain/dap_stream_ch_chain.c b/modules/channel/chain/dap_stream_ch_chain.c index 19119769bf7d5b8a09fdc32b06eccc7f1b1dbb6c..2196aa014307827e71b7a974ef0e729f50561dc3 100644 --- a/modules/channel/chain/dap_stream_ch_chain.c +++ b/modules/channel/chain/dap_stream_ch_chain.c @@ -545,6 +545,7 @@ static bool s_sync_in_chains_callback(dap_proc_thread_t *a_thread, void *a_arg) dap_chain_hash_fast_t l_atom_hash = {}; if (l_pkt_item->pkt_data_size == 0 || !l_pkt_item->pkt_data) { log_it(L_CRITICAL, "In proc thread got CHAINS stream ch packet with zero data"); + DAP_DEL_Z(l_pkt_item->pkt_data); DAP_DELETE(l_sync_request); return true; } @@ -970,14 +971,14 @@ static bool s_chain_timer_callback(void *a_arg) s_stream_ch_packet_out(l_ch, NULL); // Sending dumb packet with nothing to inform remote thats we're just skiping atoms of GDB's, nothing freezed if (l_ch_chain->state == CHAIN_STATE_SYNC_CHAINS && l_ch_chain->sent_breaks >= 3 * DAP_SYNC_TICKS_PER_SECOND) { + debug_if(s_debug_more, L_INFO, "Send one chain TSD packet"); dap_stream_ch_chain_pkt_write_unsafe(l_ch, DAP_STREAM_CH_CHAIN_PKT_TYPE_UPDATE_CHAINS_TSD, l_ch_chain->request_hdr.net_id.uint64, l_ch_chain->request_hdr.chain_id.uint64, l_ch_chain->request_hdr.cell_id.uint64, NULL, 0); l_ch_chain->sent_breaks = 0; } if (l_ch_chain->state == CHAIN_STATE_SYNC_GLOBAL_DB && l_ch_chain->sent_breaks >= 3 * DAP_SYNC_TICKS_PER_SECOND) { - if (s_debug_more) - log_it(L_INFO, "Send one global_db TSD packet (rest=%zu/%zu items)", + debug_if(s_debug_more, L_INFO, "Send one global_db TSD packet (rest=%zu/%zu items)", dap_db_log_list_get_count_rest(l_ch_chain->request_db_log), dap_db_log_list_get_count(l_ch_chain->request_db_log)); dap_stream_ch_chain_pkt_write_unsafe(l_ch, DAP_STREAM_CH_CHAIN_PKT_TYPE_UPDATE_GLOBAL_DB_TSD, diff --git a/modules/common/dap_chain_datum.c b/modules/common/dap_chain_datum.c index 4b9a26fdd7c761114cd5e0d7dbb1a028b0b85bb0..4b51e489b252ffa59afb865b9264597cbe294307 100644 --- a/modules/common/dap_chain_datum.c +++ b/modules/common/dap_chain_datum.c @@ -544,6 +544,7 @@ void dap_chain_datum_dump(dap_string_t *a_str_out, dap_chain_datum_t *a_datum, c if(l_token_size < sizeof(dap_chain_datum_token_t)){ dap_string_append_printf(a_str_out,"==Datum has incorrect size. Only %zu, while at least %zu is expected\n", l_token_size, sizeof(dap_chain_datum_token_t)); + DAP_DEL_Z(l_token); return; } dap_string_append_printf(a_str_out,"=== Datum Token Declaration ===\n"); @@ -625,6 +626,7 @@ void dap_chain_datum_dump(dap_string_t *a_str_out, dap_chain_datum_t *a_datum, c default: dap_string_append(a_str_out,"type: UNKNOWN\n"); } + DAP_DELETE(l_token); } break; case DAP_CHAIN_DATUM_TOKEN_EMISSION: { size_t l_emisssion_size = a_datum->header.data_size; diff --git a/modules/common/dap_chain_datum_token.c b/modules/common/dap_chain_datum_token.c index fea2a3477131f7890e7e275d09233b01481ab391..fcc01556ea1bcd60c4899218a3dbdf832a165bb0 100644 --- a/modules/common/dap_chain_datum_token.c +++ b/modules/common/dap_chain_datum_token.c @@ -161,6 +161,7 @@ void dap_chain_datum_token_certs_dump(dap_string_t * a_str_out, byte_t * a_data_ dap_string_append_printf(a_str_out, "%d) %s, %s, %u bytes\n", i, l_hash_str, dap_sign_type_to_str(l_sign->header.type), l_sign->header.sign_size); + DAP_DEL_Z(l_hash_str); } } diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index dde08b463e4ecd650d2d1280955b2926a302c83c..5f508e225f07b4ad682fe47f3bdc11b0c21dd8ea 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -1161,13 +1161,16 @@ static bool s_net_states_proc(dap_proc_thread_t *a_thread, void *a_arg) struct net_link *l_link, *l_link_tmp; HASH_ITER(hh, l_net_pvt->net_links, l_link, l_link_tmp) { HASH_DEL(l_net_pvt->net_links, l_link); - dap_chain_node_client_close(l_link->client_uuid); + if (l_link->link) + dap_chain_node_client_close(l_link->client_uuid); DAP_DEL_Z(l_link->link_info); + DAP_DELETE(l_link); } struct downlink *l_downlink, *l_dltmp; HASH_ITER(hh, l_net_pvt->downlinks, l_downlink, l_dltmp) { HASH_DEL(l_net_pvt->downlinks, l_downlink); dap_events_socket_delete_mt(l_downlink->worker->worker, l_downlink->esocket_uuid); + DAP_DELETE(l_downlink); } l_net_pvt->balancer_link_requests = 0; l_net_pvt->active_link = NULL; @@ -1687,7 +1690,7 @@ static int s_cli_net(int argc, char **argv, char **a_str_reply) dap_string_append(l_string_ret, "\n"); } - dap_cli_server_cmd_set_reply_text(a_str_reply, l_string_ret->str); + dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_string_ret->str); dap_string_free(l_string_ret, true); return 0; } @@ -1758,7 +1761,7 @@ static int s_cli_net(int argc, char **argv, char **a_str_reply) dap_string_append_printf( l_ret_str, "\tSpeed: %.3Lf TPS\n", l_tps ); dap_string_append_printf( l_ret_str, "\tTotal: %"DAP_UINT64_FORMAT_U"\n", l_tx_count ); dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_ret_str->str); - dap_string_free( l_ret_str, false ); + dap_string_free(l_ret_str, true); } else if (strcmp(l_stats_str, "tps") == 0) { struct timespec l_from_time_acc = {}, l_to_time_acc = {}; dap_string_t * l_ret_str = dap_string_new("Transactions per second peak values:\n"); @@ -1775,8 +1778,8 @@ static int s_cli_net(int argc, char **argv, char **a_str_reply) dap_string_append_printf(l_ret_str, "\tSpeed: %.3Lf TPS\n", l_tps); } dap_string_append_printf(l_ret_str, "\tTotal: %zu\n", l_tx_num); - dap_cli_server_cmd_set_reply_text(a_str_reply, l_ret_str->str); - dap_string_free(l_ret_str, false); + dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_ret_str->str); + dap_string_free(l_ret_str, true); } else { dap_cli_server_cmd_set_reply_text(a_str_reply, "Subcommand 'stats' requires one of parameter: tx, tps\n"); @@ -2633,12 +2636,10 @@ void dap_chain_net_deinit() pthread_rwlock_rdlock(&s_net_items_rwlock); dap_chain_net_item_t *l_current_item, *l_tmp; HASH_ITER(hh, s_net_items, l_current_item, l_tmp) { + HASH_DEL(s_net_items, l_current_item); dap_chain_net_t *l_net = l_current_item->chain_net; - dap_chain_net_pvt_t *l_net_pvt = PVT(l_net); - dap_interval_timer_delete(l_net_pvt->main_timer); - DAP_DEL_Z(l_net_pvt); + dap_interval_timer_delete(PVT(l_net)->main_timer); DAP_DEL_Z(l_net); - HASH_DEL(s_net_items, l_current_item); DAP_DEL_Z(l_current_item); } pthread_rwlock_unlock(&s_net_items_rwlock); diff --git a/modules/net/dap_chain_node_client.c b/modules/net/dap_chain_node_client.c index 6692e7dec33d725ea3400f3ca5df5202b11ebf47..ec000344e8781e77e94df92d154e8a9d635406a5 100644 --- a/modules/net/dap_chain_node_client.c +++ b/modules/net/dap_chain_node_client.c @@ -861,7 +861,7 @@ void dap_chain_node_client_close(dap_events_socket_uuid_t a_uuid) if (l_client_found) { dap_chain_node_client_t *l_client = l_client_found->client; if (l_client->sync_timer) { - DAP_DELETE(l_client->sync_timer->callback_arg); + DAP_DEL_Z(l_client->sync_timer->callback_arg); dap_timerfd_delete(l_client->sync_timer); } HASH_DEL(s_clients,l_client_found); diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index fb62016efa9ceba5df4d6393e58e7bd8804d4cc8..7ada3a3b640ee4493cd0babbe7779663e60f8ce3 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -561,8 +561,8 @@ static int s_cli_blocks(int a_argc, char ** a_argv, char **a_str_reply) l_sign_size, l_pkey_hash_str, l_addr_str ); DAP_DELETE( l_pkey_hash_str ); } - dap_cli_server_cmd_set_reply_text(a_str_reply, l_str_tmp->str); - dap_string_free(l_str_tmp,false); + dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_str_tmp->str); + dap_string_free(l_str_tmp, true); ret=0; } }else { @@ -577,13 +577,9 @@ static int s_cli_blocks(int a_argc, char ** a_argv, char **a_str_reply) } }break; case SUBCMD_LIST:{ - pthread_rwlock_rdlock(&PVT(l_blocks)->rwlock); dap_string_t * l_str_tmp = dap_string_new(NULL); - dap_string_append_printf(l_str_tmp,"%s.%s: Have %"DAP_UINT64_FORMAT_U" blocks :\n", - l_net->pub.name,l_chain->name,PVT(l_blocks)->blocks_count); dap_chain_block_cache_t * l_block_cache = NULL,*l_block_cache_tmp = NULL; - HASH_ITER(hh,PVT(l_blocks)->block_cache_first,l_block_cache, l_block_cache_tmp ) { char l_buf[50]; time_t l_ts = l_block_cache->block->hdr.ts_created; @@ -591,10 +587,11 @@ static int s_cli_blocks(int a_argc, char ** a_argv, char **a_str_reply) dap_string_append_printf(l_str_tmp,"\t%s: ts_create=%s", l_block_cache->block_hash_str, l_buf); } + dap_string_append_printf(l_str_tmp,"%s.%s: Have %"DAP_UINT64_FORMAT_U" blocks :\n", + l_net->pub.name,l_chain->name,PVT(l_blocks)->blocks_count); pthread_rwlock_unlock(&PVT(l_blocks)->rwlock); - - dap_cli_server_cmd_set_reply_text(a_str_reply, l_str_tmp->str); - dap_string_free(l_str_tmp,false); + dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_str_tmp->str); + dap_string_free(l_str_tmp, true); }break; @@ -825,8 +822,9 @@ static dap_chain_atom_verify_res_t s_callback_atom_add(dap_chain_t * a_chain, da // verify hashes and consensus dap_chain_atom_verify_res_t ret = s_callback_atom_verify (a_chain, a_atom, a_atom_size); - debug_if(s_debug_more, L_DEBUG, "Verified atom %p: %s", a_atom, ret == ATOM_ACCEPT ? "accepted" : - (ret == ATOM_REJECT ? "rejected" : "thresholded")); + + if (ret == ATOM_MOVE_TO_THRESHOLD) + ret = ATOM_REJECT; // TODO remove it when threshold will work if( ret == ATOM_ACCEPT){ int l_consensus_check = s_add_atom_to_blocks(l_blocks, a_chain->ledger, l_block_cache); @@ -853,7 +851,8 @@ static dap_chain_atom_verify_res_t s_callback_atom_add(dap_chain_t * a_chain, da }else if (ret == ATOM_REJECT ){ dap_chain_block_cache_delete(l_block_cache); } - + debug_if(s_debug_more, L_DEBUG, "Verified atom %p: %s", a_atom, ret == ATOM_ACCEPT ? "accepted" : + (ret == ATOM_REJECT ? "rejected" : "thresholded")); //s_bft_consensus_setup(l_blocks); return ret; } @@ -894,6 +893,7 @@ static dap_chain_atom_verify_res_t s_callback_atom_verify(dap_chain_t * a_chain, &l_is_genesis, &l_nonce, &l_nonce2 ) ; + DAP_DELETE(l_meta); // 2nd level consensus if(l_blocks->callback_block_verify) diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index acc61e5f06df02fd87febd5230ef1c56b1322182..53bed5336b80cc99be631bcd82291e5e9ec0191b 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -1387,7 +1387,7 @@ static int s_cli_dag(int argc, char ** argv, char **a_str_reply) // Cleaning up dap_global_db_objs_delete(l_objs, l_objs_size); dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_str_ret_tmp->str); - dap_string_free(l_str_ret_tmp,false); + dap_string_free(l_str_ret_tmp, true); // Spread new mempool changes and dag events in network - going to SYNC_ALL // dap_chain_net_sync_all(l_net); @@ -1692,7 +1692,7 @@ static int s_cli_dag(int argc, char ** argv, char **a_str_reply) dap_chain_datum_dump(l_str_tmp, l_datum, l_hash_out_type); dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_str_tmp->str); - dap_string_free(l_str_tmp,false); + dap_string_free(l_str_tmp, true); ret=0; }else { dap_cli_server_cmd_set_reply_text(a_str_reply, @@ -1730,7 +1730,7 @@ static int s_cli_dag(int argc, char ** argv, char **a_str_reply) } dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_str_tmp->str); - dap_string_free(l_str_tmp,false); + dap_string_free(l_str_tmp, true); } else if (!l_from_events_str || (strcmp(l_from_events_str,"events") == 0)) { dap_string_t * l_str_tmp = dap_string_new(NULL); pthread_rwlock_rdlock(&PVT(l_dag)->events_rwlock); @@ -1748,7 +1748,7 @@ static int s_cli_dag(int argc, char ** argv, char **a_str_reply) dap_string_append_printf(l_str_tmp,"%s.%s have total %zu events :\n", l_net->pub.name, l_chain->name, l_events_count); dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_str_tmp->str); - dap_string_free(l_str_tmp,false); + dap_string_free(l_str_tmp, true); }else if (l_from_events_str && (strcmp(l_from_events_str,"threshold") == 0) ){ dap_string_t * l_str_tmp = dap_string_new(NULL); pthread_rwlock_rdlock(&PVT(l_dag)->events_rwlock); @@ -1767,7 +1767,7 @@ static int s_cli_dag(int argc, char ** argv, char **a_str_reply) dap_string_append_printf(l_str_tmp,"%s.%s have total %zu events in threshold :\n", l_net->pub.name, l_chain->name, l_events_count); dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_str_tmp->str); - dap_string_free(l_str_tmp,false); + dap_string_free(l_str_tmp, true); }else { dap_cli_server_cmd_set_reply_text(a_str_reply, "Undefined events source for listing ");