From 9527d28b70cc21fb6d8931052781eae05da9c396 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 12 Sep 2014 17:40:09 -0400 Subject: [PATCH] Some cleanups to last PR. --- toxcore/DHT.c | 17 ++++++++++++++++- toxcore/Messenger.c | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 4830e2b1..ca4e021b 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -2336,6 +2336,9 @@ void DHT_save(DHT *dht, uint8_t *data) static void DHT_bootstrap_loaded_clients(DHT *dht) { + if (!dht->loaded_clients_list) + return; + uint32_t i; Client_data *client_list = dht->loaded_clients_list; @@ -2352,6 +2355,9 @@ static void DHT_bootstrap_loaded_clients(DHT *dht) static void getnodes_of_loaded_friend_clients(DHT *dht) { + if (!dht->loaded_friends_list) + return; + uint32_t i, j; DHT_Friend *friend_list = dht->loaded_friends_list; @@ -2373,7 +2379,7 @@ static void getnodes_of_loaded_friend_clients(DHT *dht) /* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */ int DHT_connect_after_load(DHT *dht) { - if (dht == NULL || dht->loaded_friends_list == NULL || dht->loaded_clients_list == NULL) + if (dht == NULL) return -1; getnodes_of_loaded_friend_clients(dht); @@ -2381,7 +2387,12 @@ int DHT_connect_after_load(DHT *dht) // Loaded lists were allocd, free them free(dht->loaded_friends_list); + dht->loaded_friends_list = NULL; + dht->loaded_num_friends = 0; + free(dht->loaded_clients_list); + dht->loaded_clients_list = NULL; + dht->loaded_num_clients = 0; return 0; } @@ -2400,6 +2411,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le DHT_Friend *friend_list = (DHT_Friend *)data; num = length / sizeof(DHT_Friend); + free(dht->loaded_friends_list); // Copy to loaded_friends_list dht->loaded_friends_list = calloc(num, sizeof(DHT_Friend)); @@ -2408,6 +2420,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le dht->loaded_num_friends = num; + dht->has_loaded_friends_clients = 1; } /* localize declarations */ break; @@ -2420,6 +2433,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le num = length / sizeof(Client_data); Client_data *client_list = (Client_data *)data; + free(dht->loaded_clients_list); // Copy to loaded_clients_list dht->loaded_clients_list = calloc(num, sizeof(Client_data)); @@ -2428,6 +2442,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le dht->loaded_num_clients = num; + dht->has_loaded_friends_clients = 1; } /* localize declarations */ break; diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 2a0e3f6b..21cb2671 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2818,6 +2818,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3 } memcpy(m->loaded_relays, data, length); + m->has_added_relays = 0; break; }