diff --git a/dap-sdk/core/src/dap_list.c b/dap-sdk/core/src/dap_list.c index 9fa0d16b3a8a4eb076657c49fe74f2d897fa95fb..9f891faf264f77f915c77a27d80f75888f972ebd 100755 --- a/dap-sdk/core/src/dap_list.c +++ b/dap-sdk/core/src/dap_list.c @@ -58,7 +58,7 @@ void dap_list_free1(dap_list_t *list) * dap_list_free_full: * @list: a pointer to a DapList * @free_func: the function to be called to free each element's data - * + * if NULL it calls DAP_DELETE() for it * Convenience method, which frees all the memory used by a DapList, * and calls @free_func on every element's data. */ @@ -66,7 +66,10 @@ void dap_list_free_full(dap_list_t *a_list, dap_callback_destroyed_t a_free_func { dap_list_t *l_list = a_list; while (l_list) { - a_free_func(l_list->data); + if(a_free_func) + a_free_func(l_list->data); + else + DAP_DELETE(l_list->data); l_list = l_list->next; } dap_list_free(a_list); diff --git a/modules/chain/dap_chain.c b/modules/chain/dap_chain.c index 39d3ea02f685f9eefb9ba39f1e583cc855d190e7..1e2856b2993c8d1b28fd6b3c0edce3bdab59c372 100644 --- a/modules/chain/dap_chain.c +++ b/modules/chain/dap_chain.c @@ -168,6 +168,9 @@ void dap_chain_delete(dap_chain_t * a_chain) .id = a_chain->id, .net_id = a_chain->net_id, }; + + dap_list_free_full(a_chain->atom_notifiers,NULL); + pthread_rwlock_wrlock(&s_chain_items_rwlock); HASH_FIND(hh,s_chain_items,&l_chain_item_id,sizeof(dap_chain_item_id_t),l_item); @@ -195,6 +198,7 @@ void dap_chain_delete(dap_chain_t * a_chain) DAP_DELETE(a_chain->autoproc_datum_types); pthread_rwlock_destroy(&a_chain->atoms_rwlock); pthread_rwlock_destroy(&a_chain->cell_rwlock); + pthread_rwlock_destroy(&a_chain->rwlock); pthread_rwlock_unlock(&s_chain_items_rwlock); } diff --git a/modules/chain/dap_chain_ledger.c b/modules/chain/dap_chain_ledger.c index 7afcd38f762ca62acd14a8dc1c39e907b7559e34..d2c63fac6ec3cc6a14d16aced477537fa43c1ffa 100644 --- a/modules/chain/dap_chain_ledger.c +++ b/modules/chain/dap_chain_ledger.c @@ -2343,7 +2343,7 @@ int dap_chain_ledger_tx_cache_check(dap_ledger_t *a_ledger, dap_chain_datum_tx_t if (l_err_num) { DAP_DELETE(bound_item); if ( l_list_bound_items ) - dap_list_free_full(l_list_bound_items, free); + dap_list_free_full(l_list_bound_items, NULL); HASH_ITER(hh, l_values_from_prev_tx, l_value_cur, l_tmp) { HASH_DEL(l_values_from_prev_tx, l_value_cur); DAP_DELETE(l_value_cur); @@ -2492,7 +2492,7 @@ int dap_chain_ledger_tx_cache_check(dap_ledger_t *a_ledger, dap_chain_datum_tx_t DAP_DELETE(l_value_cur); } if (!a_list_bound_items || l_err_num) { - dap_list_free_full(l_list_bound_items, free); + dap_list_free_full(l_list_bound_items, NULL); } else { *a_list_bound_items = l_list_bound_items; } @@ -2966,7 +2966,7 @@ int dap_chain_ledger_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx, ret = 1; FIN: if (l_list_bound_items) - dap_list_free_full(l_list_bound_items, free); + dap_list_free_full(l_list_bound_items, NULL); if (l_list_tx_out) dap_list_free(l_list_tx_out); for (size_t i = 1; i <= l_outs_used; i++) { @@ -3699,7 +3699,7 @@ dap_list_t *dap_chain_ledger_get_list_tx_outs_with_val(dap_ledger_t *a_ledger, c // nothing to tranfer (not enough funds) if(!l_list_used_out || compare256(l_value_transfer, a_value_need) == -1) { - dap_list_free_full(l_list_used_out, free); + dap_list_free_full(l_list_used_out, NULL); return NULL; } diff --git a/modules/channel/chain/dap_stream_ch_chain.c b/modules/channel/chain/dap_stream_ch_chain.c index 2b7c3b16edd03e773d41bed3e6ff2338cd54624e..599ce676622681a266f58dea5eaf0dd077384fd8 100644 --- a/modules/channel/chain/dap_stream_ch_chain.c +++ b/modules/channel/chain/dap_stream_ch_chain.c @@ -210,7 +210,7 @@ static void s_sync_request_delete(struct sync_request * a_sync_request) if (a_sync_request->gdb.db_iter) { a_sync_request->gdb.db_iter = dap_list_first( a_sync_request->gdb.db_iter); - dap_list_free_full( a_sync_request->gdb.db_iter, free); + dap_list_free_full( a_sync_request->gdb.db_iter, NULL); a_sync_request->gdb.db_iter = NULL; } DAP_DEL_Z(a_sync_request); diff --git a/modules/consensus/block-ton/dap_chain_cs_block_ton.c b/modules/consensus/block-ton/dap_chain_cs_block_ton.c index 3c53a8f8043e906ff61b3802d1393762ae5da095..2fe9d834ecef4bb487347f652016867bf3a027e6 100644 --- a/modules/consensus/block-ton/dap_chain_cs_block_ton.c +++ b/modules/consensus/block-ton/dap_chain_cs_block_ton.c @@ -453,7 +453,7 @@ static bool s_session_timer() { l_session->state = DAP_STREAM_CH_CHAIN_SESSION_STATE_WAIT_START; s_session_round_start(l_session); - dap_list_free_full(l_session->cur_round.validators_list, free); + dap_list_free_full(l_session->cur_round.validators_list, NULL); l_session->cur_round.validators_list = s_get_validators_addr_list(l_session); l_session->cur_round.validators_count = dap_list_length(l_session->cur_round.validators_list); @@ -610,7 +610,7 @@ static bool s_session_timer() { if (l_list_candidate) { dap_chain_hash_fast_t *l_candidate_hash = dap_list_nth_data(l_list_candidate, (rand()%l_list_candidate_size)); memcpy(&l_votefor->candidate_hash, l_candidate_hash, sizeof(dap_chain_hash_fast_t)); - dap_list_free_full(l_list_candidate, free); + dap_list_free_full(l_list_candidate, NULL); } else { dap_chain_hash_fast_t l_candidate_hash_null={0}; @@ -927,7 +927,7 @@ static bool s_session_round_finish(dap_chain_cs_block_ton_items_t *a_session) { if ( a_session->old_round.validators_list ) { // delete validators - dap_list_free_full(a_session->old_round.validators_list, free); + dap_list_free_full(a_session->old_round.validators_list, NULL); } a_session->old_round.validators_list = NULL; diff --git a/modules/global-db/dap_chain_global_db_remote.c b/modules/global-db/dap_chain_global_db_remote.c index 5581e056335d48bed1a5602589dfec1c9021a46c..9918a4bdf2a19cb82aed969901f5fa4e29a017aa 100644 --- a/modules/global-db/dap_chain_global_db_remote.c +++ b/modules/global-db/dap_chain_global_db_remote.c @@ -325,7 +325,7 @@ void dap_db_log_list_delete(dap_db_log_list_t *a_db_log_list) pthread_mutex_unlock(&a_db_log_list->list_mutex); pthread_join(a_db_log_list->thread, NULL); } - dap_list_free_full(a_db_log_list->groups, free); + dap_list_free_full(a_db_log_list->groups, NULL); dap_list_free_full(a_db_log_list->list_write, (dap_callback_destroyed_t)dap_db_log_list_delete_item); pthread_mutex_destroy(&a_db_log_list->list_mutex); DAP_DELETE(a_db_log_list); diff --git a/modules/mempool/dap_chain_mempool.c b/modules/mempool/dap_chain_mempool.c index 7b0f3feff6c265a0b8f22b29659dd5c229c26d52..b62adffae318455615c6afe5a4725f0f16c1d668 100644 --- a/modules/mempool/dap_chain_mempool.c +++ b/modules/mempool/dap_chain_mempool.c @@ -130,7 +130,7 @@ dap_hash_fast_t* dap_chain_mempool_tx_create(dap_chain_t * a_chain, dap_enc_key_ { uint256_t l_value_to_items = dap_chain_datum_tx_add_in_item_list(&l_tx, l_list_used_out); assert(EQUAL_256(l_value_to_items, l_value_transfer)); - dap_list_free_full(l_list_used_out, free); + dap_list_free_full(l_list_used_out, NULL); } // add 'out' items { @@ -332,7 +332,7 @@ int dap_chain_mempool_tx_create_massive( dap_chain_t * a_chain, dap_enc_key_t *a l_objs[i].key? l_objs[i].key :"NULL" , l_objs[i].value_len ); } - dap_list_free_full(l_list_used_out, free); + dap_list_free_full(l_list_used_out, NULL); char * l_gdb_group = dap_chain_net_get_gdb_group_mempool(a_chain); @@ -514,7 +514,7 @@ static dap_chain_datum_t* dap_chain_tx_create_cond(dap_chain_net_t *a_net, { uint256_t l_value_to_items = dap_chain_datum_tx_add_in_item_list(&l_tx, l_list_used_out); assert(EQUAL_256(l_value_to_items, l_value_transfer)); - dap_list_free_full(l_list_used_out, free); + dap_list_free_full(l_list_used_out, NULL); } // add 'out_cond' and 'out' items { diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index 700b1c3d414b237c8197793428906789e64ce049..0f163d709e8c33e00caa157ae3c43a8f208a7063 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -1281,7 +1281,7 @@ static bool s_net_states_proc(dap_proc_thread_t *a_thread, void *a_arg) { DAP_DEL_Z(((struct net_link *)l_tmp->data)->link_info); l_tmp = l_next; } - dap_list_free_full(l_net_pvt->net_links, free); + dap_list_free_full(l_net_pvt->net_links, NULL); l_net_pvt->net_links = NULL; if ( l_net_pvt->state_target != NET_STATE_OFFLINE ){ l_net_pvt->state = NET_STATE_LINKS_PREPARE; @@ -2611,7 +2611,7 @@ int s_net_load(const char * a_net_name, uint16_t a_acl_idx) DAP_DELETE (l_chain_prior->chains_path); l_list = dap_list_next(l_list); } - dap_list_free_full(l_prior_list, free); + dap_list_free_full(l_prior_list, NULL); dap_chain_t *l_chain02; diff --git a/modules/net/dap_chain_node_cli.c b/modules/net/dap_chain_node_cli.c index 8882ddfbf6071e046e54ecac985ff02aff9550bc..76ec838f98854d362637538a5cec49bdb372da6b 100644 --- a/modules/net/dap_chain_node_cli.c +++ b/modules/net/dap_chain_node_cli.c @@ -376,7 +376,7 @@ char *str_header; DAP_DELETE(str_cmd); } - dap_list_free_full(cmd_param_list, free); + dap_list_free_full(cmd_param_list, NULL); break; } } diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index e03b267b3899f2e28370ed1e07db34546834882d..3f888ff85e547e26576f7d5b95ff70c1ad71dc17 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -379,7 +379,7 @@ static int node_info_del_with_reply(dap_chain_net_t * a_net, dap_chain_node_info dap_chain_node_alias_delete(a_net, alias); list = dap_list_next(list); } - dap_list_free_full(list_aliases, (dap_callback_destroyed_t) free); + dap_list_free_full(list_aliases, NULL); } // set text response dap_chain_node_cli_set_reply_text(str_reply, "node deleted"); @@ -565,7 +565,7 @@ static int node_info_dump_with_reply(dap_chain_net_t * a_net, dap_chain_node_add dap_string_append_printf(aliases_string, "\nalias %s", alias); list = dap_list_next(list); } - dap_list_free_full(list_aliases, (dap_callback_destroyed_t) free); + dap_list_free_full(list_aliases, NULL); } else dap_string_append(aliases_string, "\nno aliases"); @@ -1180,7 +1180,7 @@ int com_node(int a_argc, char ** a_argv, char **a_str_reply) if(l_is_auto) { //start background thread for testing connect to the nodes dap_chain_node_ping_background_start(l_net, l_node_list); - dap_list_free_full(l_node_list, free); + dap_list_free_full(l_node_list, NULL); } @@ -4499,7 +4499,7 @@ int cmd_gdb_export(int argc, char ** argv, char ** a_str_reply) json_object_array_add(l_json, l_json_group_inner); dap_store_obj_free(l_data, l_data_size); } - dap_list_free_full(l_groups_list, free); + dap_list_free_full(l_groups_list, NULL); if (json_object_to_file(l_path, l_json) == -1) { #if JSON_C_MINOR_VERSION<15 log_it(L_CRITICAL, "Couldn't export JSON to file, error code %d", errno ); diff --git a/modules/net/dap_chain_node_cli_cmd_tx.c b/modules/net/dap_chain_node_cli_cmd_tx.c index e31057a9e0e55aab67dd0d825d6232057826dc79..1fe9286fb8f9b1163ebdce5b69c91f0a79419b96 100644 --- a/modules/net/dap_chain_node_cli_cmd_tx.c +++ b/modules/net/dap_chain_node_cli_cmd_tx.c @@ -988,7 +988,7 @@ int com_ledger(int a_argc, char ** a_argv, char **a_str_reply) for (dap_list_t *l_list = l_token_list; l_list; l_list = dap_list_next(l_list)) { dap_string_append(l_str_ret, (char *)l_list->data); } - dap_list_free_full(l_token_list, free); + dap_list_free_full(l_token_list, NULL); dap_chain_node_cli_set_reply_text(a_str_reply, l_str_ret->str); dap_string_free(l_str_ret, true); return 0; diff --git a/modules/net/dap_chain_node_ping.c b/modules/net/dap_chain_node_ping.c index 039819fe3654552272fce61e6e4f6751b146531f..2f4f07c428981a6fc8884e869f982d8f0aed50f6 100644 --- a/modules/net/dap_chain_node_ping.c +++ b/modules/net/dap_chain_node_ping.c @@ -274,7 +274,7 @@ static void* node_ping_background_proc(void *a_arg) memcpy(l_node_addr_tmp, s_node_addr_ping, sizeof(dap_chain_node_addr_t)); DAP_DELETE(s_node_addr_ping); s_node_addr_ping = l_node_addr_tmp; - dap_list_free_full(l_node_list0, free); + dap_list_free_full(l_node_list0, NULL); return 0; } diff --git a/modules/net/srv/dap_chain_net_srv_order.c b/modules/net/srv/dap_chain_net_srv_order.c index 26b841cb7d38a5e644561694a85fb8d930ab26f6..86a2ab62dc40fff2ec301d4667f2aa7f1ec1b54e 100644 --- a/modules/net/srv/dap_chain_net_srv_order.c +++ b/modules/net/srv/dap_chain_net_srv_order.c @@ -86,7 +86,7 @@ int dap_chain_net_srv_order_init(void) */ void dap_chain_net_srv_order_deinit() { - dap_list_free_full(s_order_notify_callbacks, free); + dap_list_free_full(s_order_notify_callbacks, NULL); } size_t dap_chain_net_srv_order_get_size(dap_chain_net_srv_order_t *a_order) diff --git a/modules/service/stake/dap_chain_net_srv_stake.c b/modules/service/stake/dap_chain_net_srv_stake.c index 9edc1f3b0720df6149bc499006f7d1c166a88772..c5f3e64720ef048247a1b43d7a8c13ed582a8d84 100644 --- a/modules/service/stake/dap_chain_net_srv_stake.c +++ b/modules/service/stake/dap_chain_net_srv_stake.c @@ -379,7 +379,7 @@ static dap_chain_datum_tx_t *s_stake_tx_create(dap_chain_net_srv_stake_item_t *a // add 'in' items to sell uint256_t l_value_to_items = dap_chain_datum_tx_add_in_item_list(&l_tx, l_list_used_out); - dap_list_free_full(l_list_used_out, free); + dap_list_free_full(l_list_used_out, NULL); if (!EQUAL_256(l_value_to_items,l_value_sell)) { dap_chain_datum_tx_delete(l_tx); DAP_DELETE(l_owner_addr); diff --git a/modules/service/xchange/dap_chain_net_srv_xchange.c b/modules/service/xchange/dap_chain_net_srv_xchange.c index 017f40e800110f17bf5899a0b78c20c06aadb325..b75af2c623964437a0532e05835e115b74335ebc 100644 --- a/modules/service/xchange/dap_chain_net_srv_xchange.c +++ b/modules/service/xchange/dap_chain_net_srv_xchange.c @@ -177,7 +177,7 @@ static dap_chain_datum_tx_t *s_xchange_tx_create_request(dap_chain_net_srv_xchan // add 'in' items to sell uint256_t l_value_to_items = dap_chain_datum_tx_add_in_item_list(&l_tx, l_list_used_out); - dap_list_free_full(l_list_used_out, free); + dap_list_free_full(l_list_used_out, NULL); if (compare256(l_value_to_items, l_value_sell) != 0) { dap_chain_datum_tx_delete(l_tx); DAP_DELETE(l_seller_addr); @@ -252,7 +252,7 @@ static dap_chain_datum_tx_t *s_xchange_tx_create_exchange(dap_chain_net_srv_xcha DAP_DELETE(l_receipt); // add 'in' items to sell uint256_t l_value_to_items = dap_chain_datum_tx_add_in_item_list(&l_tx, l_list_used_out); - dap_list_free_full(l_list_used_out, free); + dap_list_free_full(l_list_used_out, NULL); if (compare256(l_value_to_items, l_value_buy) != 0) { dap_chain_datum_tx_delete(l_tx); DAP_DELETE(l_seller_addr);