summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2017-08-01 16:38:51 +0200
committerLinus Nordberg <linus@nordu.net>2017-08-01 18:19:50 +0200
commit1d8c415e27062723c62de09c434479fc22d23b79 (patch)
tree9beed272b3e4b9484f181e1da112e6793ebd2dc0
parentb731b45fa8651fd3b386a96892d8e08856d5072a (diff)
Move allocation of memory to not have to free in error case.
-rw-r--r--radsecproxy.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/radsecproxy.c b/radsecproxy.c
index e3a3814..142d069 100644
--- a/radsecproxy.c
+++ b/radsecproxy.c
@@ -192,12 +192,7 @@ void freebios(struct gqueue *q) {
}
struct client *addclient(struct clsrvconf *conf, uint8_t lock) {
- struct client *new = malloc(sizeof(struct client));
-
- if (!new) {
- debug(DBG_ERR, "malloc failed");
- return NULL;
- }
+ struct client *new = NULL;
if (lock)
pthread_mutex_lock(conf->lock);
@@ -211,7 +206,11 @@ struct client *addclient(struct clsrvconf *conf, uint8_t lock) {
}
}
- memset(new, 0, sizeof(struct client));
+ new = calloc(1, sizeof(struct client));
+ if (!new) {
+ debug(DBG_ERR, "malloc failed");
+ return NULL;
+ }
new->conf = conf;
if (conf->pdef->addclient)
conf->pdef->addclient(new);