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 16:38:51 +0200
commit91f288e0d343aea949fe6f131a261ce7706ac661 (patch)
tree1ecc14093bdff06a339ae241c28e53577afde095
parentf99c3a90010dbfbf74e409458692af95370159c8 (diff)
Move allocation of memory, making error case simpler.coverity
-rw-r--r--radsecproxy.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/radsecproxy.c b/radsecproxy.c
index 12910ed..4fd4788 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);
@@ -237,12 +232,15 @@ struct client *addclient(struct clsrvconf *conf, uint8_t lock) {
if (lock)
pthread_mutex_unlock(conf->lock);
debug(DBG_ERR, "malloc failed");
- free(new);
return NULL;
}
}
- 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);