summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-03-06 14:30:14 +0100
committerLinus Nordberg <linus@nordu.net>2011-03-06 14:30:14 +0100
commitf87be530d67823a5d82367468e33d58b201ebee1 (patch)
treecd56779320f50aefeb1357dd072c686e59353ac3
parentc1de57efcaa05f4127a73f99c9f366149dc4b98f (diff)
Don't free config object until we destroy the context.
-rw-r--r--lib/conf.c28
-rw-r--r--lib/include/radsec/radsec-impl.h2
-rw-r--r--lib/radsec.c5
3 files changed, 25 insertions, 10 deletions
diff --git a/lib/conf.c b/lib/conf.c
index ff225ce..c8b2a46 100644
--- a/lib/conf.c
+++ b/lib/conf.c
@@ -31,9 +31,12 @@
int
rs_context_read_config(struct rs_context *ctx, const char *config_file)
{
-
/* FIXME: Missing some error handling in rs_context_read_config(). */
+ cfg_t *cfg, *cfg_config, *cfg_server;
+ int i, j;
+ const char *s;
+
cfg_opt_t server_opts[] =
{
CFG_STR ("hostname", NULL, CFGF_NONE),
@@ -58,8 +61,6 @@ rs_context_read_config(struct rs_context *ctx, const char *config_file)
CFG_SEC ("config", config_opts, CFGF_TITLE | CFGF_MULTI),
CFG_END ()
};
- cfg_t *cfg, *cfg_config, *cfg_server;
- int i, j;
cfg = cfg_init (opts, CFGF_NONE);
if (cfg_parse (cfg, config_file) == CFG_PARSE_ERROR)
@@ -81,7 +82,11 @@ rs_context_read_config(struct rs_context *ctx, const char *config_file)
else
ctx->realms = r;
cfg_config = cfg_getnsec (cfg, "config", i);
- r->name = strdup (cfg_title (cfg_config));
+ s = cfg_title (cfg_config);
+ if (s == NULL)
+ return rs_err_ctx_push_fl (ctx, RSE_CONFIG, __FILE__, __LINE__,
+ "missing config name");
+ r->name = strdup (s);
typestr = cfg_getstr (cfg_config, "type");
if (!strcmp (typestr, "UDP"))
@@ -98,10 +103,10 @@ rs_context_read_config(struct rs_context *ctx, const char *config_file)
r->timeout = cfg_getint (cfg_config, "timeout");
r->retries = cfg_getint (cfg_config, "retries");
- r->cacertfile = strdup (cfg_getstr (cfg_config, "cacertfile"));
- /*r->cacertpath = strdup (cfg_getstr (cfg_config, "cacertpath"));*/
- r->certfile = strdup (cfg_getstr (cfg_config, "certfile"));
- r->certkeyfile = strdup (cfg_getstr (cfg_config, "certkeyfile"));
+ r->cacertfile = cfg_getstr (cfg_config, "cacertfile");
+ /*r->cacertpath = cfg_getstr (cfg_config, "cacertpath");*/
+ r->certfile = cfg_getstr (cfg_config, "certfile");
+ r->certkeyfile = cfg_getstr (cfg_config, "certkeyfile");
/* Add peers, one per server stanza. */
for (j = 0; j < cfg_size (cfg_config, "server"); j++)
@@ -115,10 +120,13 @@ rs_context_read_config(struct rs_context *ctx, const char *config_file)
cfg_server = cfg_getnsec (cfg_config, "server", j);
_rs_resolv (&p->addr, r->type, cfg_getstr (cfg_server, "hostname"),
cfg_getstr (cfg_server, "service"));
- p->secret = strdup (cfg_getstr (cfg_server, "secret"));
+ p->secret = cfg_getstr (cfg_server, "secret");
}
}
- cfg_free (cfg);
+
+ /* Save config object in context, for freeing in
+ rs_context_destroy(). */
+ ctx->cfg = cfg;
return RSE_OK;
}
diff --git a/lib/include/radsec/radsec-impl.h b/lib/include/radsec/radsec-impl.h
index 932e5d2..963c821 100644
--- a/lib/include/radsec/radsec-impl.h
+++ b/lib/include/radsec/radsec-impl.h
@@ -5,6 +5,7 @@
#include <freeradius/libradius.h>
#include <event2/util.h>
+#include <confuse.h>
#if defined(RS_ENABLE_TLS)
#include <openssl/ssl.h>
#endif
@@ -61,6 +62,7 @@ struct rs_context {
struct rs_alloc_scheme alloc_scheme;
struct rs_error *err;
fr_randctx fr_randctx;
+ cfg_t *cfg;
};
struct rs_connection {
diff --git a/lib/radsec.c b/lib/radsec.c
index f8bd246..afb871e 100644
--- a/lib/radsec.c
+++ b/lib/radsec.c
@@ -142,6 +142,11 @@ void rs_context_destroy(struct rs_context *ctx)
r = r->next;
rs_free (ctx, tmp);
}
+
+ if (ctx->cfg)
+ cfg_free (ctx->cfg);
+ ctx->cfg = NULL;
+
rs_free (ctx, ctx);
}