- hosts[i]->socket = -1;
- hosts[i]->next = NULL;
- if (i>0) hosts[i-1]->next = hosts[i];
- gettimeofday(&(hosts[i]->last_ping_received), (struct timezone *) NULL);
+ cur_host->socket = -1;
+ cur_host->next = NULL;
+ gettimeofday(&(cur_host->last_ping_received), (struct timezone *) NULL);
+
+ if (hosts == NULL) {
+ hosts = cur_host;
+ host_list_end = cur_host;
+ } else {
+ host_list_end->next = cur_host;
+ host_list_end = cur_host;
+ }
+
+ free(key_buf);