summaryrefslogtreecommitdiff
path: root/lib/radsec.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-03-21 14:32:31 +0100
committerLinus Nordberg <linus@nordu.net>2011-03-21 14:32:31 +0100
commita177887c740c173948fc7dbf96f726616885c407 (patch)
treed6ff0e9cdd8cc9fd614ec118d04bc1d010df291a /lib/radsec.c
parent6cefe9483fda567d9db2447bda2f09f63d1101af (diff)
Memory alloc/free cleanup for contexts.
(rs_context_create): Don't touch *ctx on failure. Keep allocation and zeroing of allocated memory together. (rs_context_destroy): Fix typo. (rs_context_destroy): Don't rs_free the context since it's allocated with calloc.
Diffstat (limited to 'lib/radsec.c')
-rw-r--r--lib/radsec.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/radsec.c b/lib/radsec.c
index c7ba68c..6e68950 100644
--- a/lib/radsec.c
+++ b/lib/radsec.c
@@ -32,10 +32,8 @@ rs_context_create (struct rs_context **ctx)
{
struct rs_context *h;
- if (ctx)
- *ctx = NULL;
- h = (struct rs_context *) malloc (sizeof(struct rs_context));
- if (!h)
+ h = calloc (1, sizeof(*h));
+ if (h == NULL)
return RSE_NOMEM;
#if defined (RS_ENABLE_TLS)
@@ -47,11 +45,10 @@ rs_context_create (struct rs_context **ctx)
#endif
debug_init ("libradsec"); /* radsecproxy compat, FIXME: remove */
- memset (h, 0, sizeof(struct rs_context));
fr_randinit (&h->fr_randctx, 0);
fr_rand_seed (NULL, 0);
- if (ctx)
+ if (ctx != NULL)
*ctx = h;
return RSE_OK;
@@ -158,7 +155,7 @@ rs_context_destroy (struct rs_context *ctx)
p = p->next;
rs_free (ctx, tmp);
}
- free (ctx, r->name);
+ free (r->name);
r = r->next;
rs_free (ctx, tmp);
}
@@ -174,7 +171,7 @@ rs_context_destroy (struct rs_context *ctx)
rs_free (ctx, ctx->config);
}
- rs_free (ctx, ctx);
+ free (ctx);
}
int