diff --git a/src/tofu.c b/src/tofu.c
index de3746563ed3e0c515a5c52a053f3a535fda5e09..af5d9f20d78558b3ff7dc9253bef53f2deef1d25 100644
--- a/src/tofu.c
+++ b/src/tofu.c
@@ -175,13 +175,14 @@ tofu->callback = cb;
tofu->cb_data = cb_data;
SSL_CTX_set_cert_verify_callback(ssl_ctx, verify_callback, tofu);
+ tofu->known_hosts = NULL;
+
FILE *f = fopen(tofu->known_hosts_path, "r");
if (!f) {
return;
}
size_t n = 0;
char *line = NULL;
- tofu->known_hosts = NULL;
while (getline(&line, &n, f) != -1) {
struct known_host *host = calloc(1, sizeof(struct known_host));
char *tok = strtok(line, " ");