Skip to content

Commit

Permalink
Move allocation of memory, making error case simpler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Linus Nordberg committed Aug 1, 2017
1 parent 88de41d commit 7e22f21
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions radsecproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 7e22f21

Please sign in to comment.