diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 64aa1162..1db98577 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -296,6 +296,10 @@ loop_top: c_sleep(500); } + for (i = 0; i < NUM_DHT_FRIENDS; ++i) { + ck_assert_msg(DHT_delfriend(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, 1) == 0, "Failed to delete friend"); + } + for (i = 0; i < NUM_DHT; ++i) { void *n = dhts[i]->net; kill_DHT(dhts[i]); diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 0f972fda..49a7bb0d 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -813,11 +813,20 @@ static int dealloc_buckets(DHT_Bucket *bucket) /* pk doesn't matter, want any nodes from both lower buckets. */ uint8_t pk[crypto_box_PUBLICKEYBYTES] = {0}; - int ret = recursive_DHT_bucket_get_nodes(bucket, bucket->client_list, DHT_BUCKET_NODES, pk, 1, 1); + + Client_data nodes[DHT_BUCKET_NODES]; + int ret = recursive_DHT_bucket_get_nodes(bucket, nodes, DHT_BUCKET_NODES, pk, 1, 1); recursive_free_buckets(bucket); bucket->empty = 0; + if (ret >= 1) { + bucket->client_list = calloc(DHT_BUCKET_NODES, sizeof(Client_data)); + + if (bucket->client_list) + memcpy(bucket->client_list, nodes, sizeof(nodes)); + } + if (ret >= 0) { return 0; } else {