knotd_conf_mod and knotd_conf_free
I find knotd_conf_mod and knotd_conf_free are not always in pairs. For example, in geoip.c:
knotd_conf_t conf = knotd_conf_mod(mod, MOD_TTL);
ctx->ttl = conf.single.integer;
conf = knotd_conf_mod(mod, MOD_MODE);
ctx->mode = conf.single.option;
// Initialize the dname trie.
ctx->geo_trie = trie_create(NULL);
if (ctx->geo_trie == NULL) {
free_geoip_ctx(ctx);
return KNOT_ENOMEM;
}
if (ctx->mode == MODE_GEODB) {
// Initialize geodb.
conf = knotd_conf_mod(mod, MOD_GEODB_FILE);
ctx->geodb = geodb_open(conf.single.string);
if (ctx->geodb == NULL) {
knotd_mod_log(mod, LOG_ERR, "failed to open geo DB");
free_geoip_ctx(ctx);
return KNOT_EINVAL;
}
// Load configured geodb keys.
conf = knotd_conf_mod(mod, MOD_GEODB_KEY);
if (conf.count > GEODB_MAX_DEPTH) {
knotd_mod_log(mod, LOG_ERR, "maximal number of geodb-key items (%d) exceeded",
GEODB_MAX_DEPTH);
knotd_conf_free(&conf);
free_geoip_ctx(ctx);
return KNOT_EINVAL;
}
ctx->path_count = conf.count;
for (size_t i = 0; i < conf.count; i++) {
if (parse_geodb_path(&ctx->paths[i], (char *)conf.multi[i].string) != 0) {
knotd_mod_log(mod, LOG_ERR, "unrecognized geodb-key format");
knotd_conf_free(&conf);
free_geoip_ctx(ctx);
return KNOT_EINVAL;
}
}
knotd_conf_free(&conf);
}
knotd_conf_mod(mod, MOD_TTL) and knotd_conf_mod(mod,MOD_MODE) are not freed. And I also found other modules/files do somethings like that. I don't know when and why.