Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2795,28 +2795,25 @@ static State_Load_Status dht_load_state_callback(void *_Nonnull outer, const uin
break;
}

mem_delete(dht->mem, dht->loaded_nodes_list);

// Copy to loaded_clients_list
// TODO(Green-Sky): This allocates 130KiB, might be worth reducing or retrying with smaller, partial allocations.
Node_format *nodes = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));

if (nodes == nullptr) {
LOGGER_ERROR(dht->log, "could not allocate %u nodes", (unsigned int)MAX_SAVED_DHT_NODES);
dht->loaded_num_nodes = 0;
break;
}

const int num = unpack_nodes(nodes, MAX_SAVED_DHT_NODES, nullptr, data, length, false);

if (num < 0) {
// Unpack error happened, we ignore it.
dht->loaded_num_nodes = 0;
if (num <= 0) {
// Unpack error happened or list was empty, we ignore it.
mem_delete(dht->mem, nodes);
} else {
mem_delete(dht->mem, dht->loaded_nodes_list);
dht->loaded_num_nodes = num;
dht->loaded_nodes_list = nodes;
}

dht->loaded_nodes_list = nodes;

break;
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ bool dht_bootstrap(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uin
*/
bool dht_bootstrap_from_address(DHT *_Nonnull dht, const char *_Nonnull address, bool ipv6enabled, bool dns_enabled, uint16_t port, const uint8_t *_Nonnull public_key);

/** @brief Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.
/** @brief Start sending packets after DHT loaded_nodes_list is set.
*
* @retval 0 if successful
* @retval -1 otherwise
Expand Down
Loading