diff options
author | iphydf <iphydf@users.noreply.github.com> | 2020-05-03 01:09:06 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2020-05-03 14:13:48 +0000 |
commit | 88b90c82259f86470cf6eba8684e8d9b4cd61bc3 (patch) | |
tree | 90e052389ffacec791019a096837a670e205b225 /toxcore | |
parent | 7b758f66dbc550fa52ed66fd7f8b81f8ed37a94e (diff) |
Fix a bug in savedata loading when malloc fails.
Also added a bunch of asserts to tests where they don't check allocs.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index b3017259..7c9263cd 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -2917,6 +2917,12 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat | |||
2917 | // Copy to loaded_clients_list | 2917 | // Copy to loaded_clients_list |
2918 | dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); | 2918 | dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); |
2919 | 2919 | ||
2920 | if (dht->loaded_nodes_list == nullptr) { | ||
2921 | LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES); | ||
2922 | dht->loaded_num_nodes = 0; | ||
2923 | break; | ||
2924 | } | ||
2925 | |||
2920 | const int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, 0); | 2926 | const int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, 0); |
2921 | 2927 | ||
2922 | if (num > 0) { | 2928 | if (num > 0) { |