@@ -110,10 +110,10 @@ struct DHT {
110110 uint8_t self_public_key [CRYPTO_PUBLIC_KEY_SIZE ];
111111 uint8_t self_secret_key [CRYPTO_SECRET_KEY_SIZE ];
112112
113- DHT_Friend * friends_list ;
113+ DHT_Friend * owner friends_list ;
114114 uint16_t num_friends ;
115115
116- Node_format * loaded_nodes_list ;
116+ Node_format * owner loaded_nodes_list ;
117117 uint32_t loaded_num_nodes ;
118118 unsigned int loaded_nodes_index ;
119119
@@ -370,7 +370,7 @@ int dht_create_packet(const Memory *mem, const Random *rng,
370370 uint8_t * packet , size_t length )
371371{
372372 uint8_t nonce [CRYPTO_NONCE_SIZE ];
373- uint8_t * encrypted = (uint8_t * )mem_balloc (mem , plain_length + CRYPTO_MAC_SIZE );
373+ uint8_t * owner encrypted = (uint8_t * owner )mem_balloc (mem , plain_length + CRYPTO_MAC_SIZE );
374374
375375 if (encrypted == nullptr ) {
376376 return -1 ;
@@ -920,7 +920,7 @@ static void sort_client_list(const Memory *mem, Client_data *list, uint64_t cur_
920920{
921921 // Pass comp_public_key to qsort with each Client_data entry, so the
922922 // comparison function can use it as the base of comparison.
923- DHT_Cmp_Data * cmp_list = (DHT_Cmp_Data * )mem_valloc (mem , length , sizeof (DHT_Cmp_Data ));
923+ DHT_Cmp_Data * owner cmp_list = (DHT_Cmp_Data * owner )mem_valloc (mem , length , sizeof (DHT_Cmp_Data ));
924924
925925 if (cmp_list == nullptr ) {
926926 return ;
@@ -1591,13 +1591,14 @@ int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
15911591 return 0 ;
15921592 }
15931593
1594- DHT_Friend * const temp = (DHT_Friend * )mem_vrealloc (dht -> mem , dht -> friends_list , dht -> num_friends + 1 , sizeof (DHT_Friend ));
1594+ bool ok ;
1595+ dht -> friends_list =
1596+ (DHT_Friend * owner )mem_vresize (dht -> mem , dht -> friends_list , dht -> num_friends + 1 , sizeof (DHT_Friend ), & ok );
15951597
1596- if (temp == nullptr ) {
1598+ if (! ok ) {
15971599 return -1 ;
15981600 }
15991601
1600- dht -> friends_list = temp ;
16011602 DHT_Friend * const dht_friend = & dht -> friends_list [dht -> num_friends ];
16021603 * dht_friend = empty_dht_friend ;
16031604 memcpy (dht_friend -> public_key , public_key , CRYPTO_PUBLIC_KEY_SIZE );
@@ -1641,13 +1642,14 @@ int dht_delfriend(DHT *dht, const uint8_t *public_key, uint32_t lock_token)
16411642 return 0 ;
16421643 }
16431644
1644- DHT_Friend * const temp = (DHT_Friend * )mem_vrealloc (dht -> mem , dht -> friends_list , dht -> num_friends , sizeof (DHT_Friend ));
1645+ bool ok ;
1646+ dht -> friends_list =
1647+ (DHT_Friend * owner )mem_vresize (dht -> mem , dht -> friends_list , dht -> num_friends , sizeof (DHT_Friend ), & ok );
16451648
1646- if (temp == nullptr ) {
1649+ if (! ok ) {
16471650 return -1 ;
16481651 }
16491652
1650- dht -> friends_list = temp ;
16511653 return 0 ;
16521654}
16531655
@@ -1694,8 +1696,10 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
16941696 const uint64_t temp_time = mono_time_get (dht -> mono_time );
16951697
16961698 uint32_t num_nodes = 0 ;
1697- Client_data * * client_list = (Client_data * * )mem_valloc (dht -> mem , list_count * 2 , sizeof (Client_data * ));
1698- IPPTsPng * * assoc_list = (IPPTsPng * * )mem_valloc (dht -> mem , list_count * 2 , sizeof (IPPTsPng * ));
1699+ Client_data * * owner client_list =
1700+ (Client_data * * owner )mem_valloc (dht -> mem , list_count * 2 , sizeof (Client_data * ));
1701+ IPPTsPng * * owner assoc_list =
1702+ (IPPTsPng * * owner )mem_valloc (dht -> mem , list_count * 2 , sizeof (IPPTsPng * ));
16991703 unsigned int sort = 0 ;
17001704 bool sort_ok = false;
17011705
@@ -2513,15 +2517,16 @@ static int handle_lan_discovery(void *object, const IP_Port *source, const uint8
25132517
25142518/*----------------------------------------------------------------------------------*/
25152519
2516- DHT * new_dht (const Logger * log , const Memory * mem , const Random * rng , const Network * ns ,
2517- Mono_Time * mono_time , Networking_Core * net ,
2518- bool hole_punching_enabled , bool lan_discovery_enabled )
2520+ DHT * owner new_dht (
2521+ const Logger * log , const Memory * mem , const Random * rng , const Network * ns ,
2522+ Mono_Time * mono_time , Networking_Core * net ,
2523+ bool hole_punching_enabled , bool lan_discovery_enabled )
25192524{
25202525 if (net == nullptr ) {
25212526 return nullptr ;
25222527 }
25232528
2524- DHT * const dht = (DHT * )mem_alloc (mem , sizeof (DHT ));
2529+ DHT * const owner dht = (DHT * owner )mem_alloc (mem , sizeof (DHT ));
25252530
25262531 if (dht == nullptr ) {
25272532 LOGGER_ERROR (log , "failed to allocate DHT struct (%ld bytes)" , (unsigned long )sizeof (DHT ));
@@ -2620,7 +2625,7 @@ void do_dht(DHT *dht)
26202625 ping_iterate (dht -> ping );
26212626}
26222627
2623- void kill_dht (DHT * dht )
2628+ void kill_dht (DHT * owner dht )
26242629{
26252630 if (dht == nullptr ) {
26262631 return ;
@@ -2693,7 +2698,8 @@ void dht_save(const DHT *dht, uint8_t *data)
26932698 /* get right offset. we write the actual header later. */
26942699 data = state_write_section_header (data , DHT_STATE_COOKIE_TYPE , 0 , 0 );
26952700
2696- Node_format * clients = (Node_format * )mem_valloc (dht -> mem , MAX_SAVED_DHT_NODES , sizeof (Node_format ));
2701+ Node_format * owner clients =
2702+ (Node_format * owner )mem_valloc (dht -> mem , MAX_SAVED_DHT_NODES , sizeof (Node_format ));
26972703
26982704 if (clients == nullptr ) {
26992705 LOGGER_ERROR (dht -> log , "could not allocate %u nodes" , MAX_SAVED_DHT_NODES );
@@ -2790,7 +2796,8 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat
27902796 mem_delete (dht -> mem , dht -> loaded_nodes_list );
27912797
27922798 // Copy to loaded_clients_list
2793- Node_format * nodes = (Node_format * )mem_valloc (dht -> mem , MAX_SAVED_DHT_NODES , sizeof (Node_format ));
2799+ Node_format * owner nodes =
2800+ (Node_format * owner )mem_valloc (dht -> mem , MAX_SAVED_DHT_NODES , sizeof (Node_format ));
27942801
27952802 if (nodes == nullptr ) {
27962803 LOGGER_ERROR (dht -> log , "could not allocate %u nodes" , MAX_SAVED_DHT_NODES );
0 commit comments