Commit 5f1655a6 authored by Daniel Salzman's avatar Daniel Salzman

conf: fix memory leaks if invalid configuration

parent 67ed1f81
......@@ -544,6 +544,7 @@ int main(int argc, char **argv)
if (ret != KNOT_EOK) {
log_fatal("failed to load configuration file (%s)",
knot_strerror(ret));
conf_free(new_conf, false);
rc = 1;
goto exit;
}
......@@ -565,7 +566,8 @@ int main(int argc, char **argv)
if (res != KNOT_EOK) {
log_fatal("failed to use configuration (%s)", knot_strerror(res));
conf_free(new_conf, false);
return EXIT_FAILURE;
rc = 1;
goto exit;
}
conf_update(new_conf);
......@@ -625,7 +627,8 @@ exit:
knot_tsig_key_free(&r_key);
conf_free(conf(), false);
log_close();
return rc;
return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
static int cmd_stop(cmd_args_t *args)
......
......@@ -341,6 +341,7 @@ int main(int argc, char **argv)
if (ret != KNOT_EOK) {
log_fatal("failed to initialize configuration database "
"(%s)", knot_strerror(ret));
log_close();
return EXIT_FAILURE;
}
......@@ -350,6 +351,7 @@ int main(int argc, char **argv)
log_fatal("failed to load configuration file (%s)",
knot_strerror(ret));
conf_free(new_conf, false);
log_close();
return EXIT_FAILURE;
}
......@@ -360,6 +362,7 @@ int main(int argc, char **argv)
if (ret != KNOT_EOK) {
log_fatal("failed to open configuration database '%s' "
"(%s)", config_db, knot_strerror(ret));
log_close();
return EXIT_FAILURE;
}
}
......@@ -369,6 +372,7 @@ int main(int argc, char **argv)
if (res != KNOT_EOK) {
log_fatal("failed to use configuration (%s)", knot_strerror(res));
conf_free(new_conf, false);
log_close();
return EXIT_FAILURE;
}
......
......@@ -489,16 +489,14 @@ int server_reload(server_t *server, const char *cf)
return KNOT_EINVAL;
}
int ret = KNOT_EOK;
if (cf != NULL) {
log_info("reloading configuration file '%s'", cf);
conf_t *new_conf = NULL;
ret = conf_clone(&new_conf);
int ret = conf_clone(&new_conf);
if (ret != KNOT_EOK) {
log_fatal("failed to initialize configuration (%s)",
knot_strerror(ret));
return EXIT_FAILURE;
return ret;
}
/* Import the configuration file. */
......@@ -507,7 +505,7 @@ int server_reload(server_t *server, const char *cf)
log_fatal("failed to load configuration file (%s)",
knot_strerror(ret));
conf_free(new_conf, false);
return EXIT_FAILURE;
return ret;
}
/* Run post-open config operations. */
......@@ -516,7 +514,7 @@ int server_reload(server_t *server, const char *cf)
log_fatal("failed to use configuration (%s)",
knot_strerror(res));
conf_free(new_conf, false);
return EXIT_FAILURE;
return ret;
}
conf_update(new_conf);
......@@ -530,7 +528,7 @@ int server_reload(server_t *server, const char *cf)
log_info("configuration reloaded");
return ret;
return KNOT_EOK;
}
void server_stop(server_t *server)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment