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:25:37 +0200
commit7e22f21430275051cb212ab626957c93d71c9e8a (patch)
tree4e424ed8408cb384ba970a5c168db82162e310b8
parent88de41d15164364d7faaa9c61c6d85ab9c5f3125 (diff)
Move allocation of memory, making error case simpler.
-rw-r--r--radsecproxy.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/radsecproxy.c b/radsecproxy.c
index 517a094..b333326 100644
--- a/radsecproxy.c
+++ b/radsecproxy.c
@@ -222,12 +222,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);
@@ -241,7 +236,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);