/* allocate an bind_conf struct for a bind line, and chain it to the frontend <fe>.
* If <arg> is not NULL, it is duplicated into ->arg to store useful config
- * information for error reporting.
+ * information for error reporting. NULL is returned on error.
*/
static inline struct bind_conf *bind_conf_alloc(struct proxy *fe, const char *file,
int line, const char *arg, struct xprt_ops *xprt)
{
struct bind_conf *bind_conf = calloc(1, sizeof(struct bind_conf));
+ if (!bind_conf)
+ goto err;
+
bind_conf->file = strdup(file);
+ if (!bind_conf->file)
+ goto err;
bind_conf->line = line;
- LIST_ADDQ(&fe->conf.bind, &bind_conf->by_fe);
- if (arg)
+ if (arg) {
bind_conf->arg = strdup(arg);
+ if (!bind_conf->arg)
+ goto err;
+ }
+ LIST_ADDQ(&fe->conf.bind, &bind_conf->by_fe);
bind_conf->settings.ux.uid = -1;
bind_conf->settings.ux.gid = -1;
bind_conf->settings.ux.mode = 0;
#endif
LIST_INIT(&bind_conf->listeners);
return bind_conf;
+
+ err:
+ if (bind_conf) {
+ ha_free(&bind_conf->file);
+ ha_free(&bind_conf->arg);
+ }
+ ha_free(&bind_conf);
+ return NULL;
}
static inline const char *listener_state_str(const struct listener *l)
}
bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
-
+ if (!bind_conf) {
+ ha_alert("Out of memory error.\n");
+ err_code |= ERR_ALERT | ERR_ABORT;
+ goto out;
+ }
/* use default settings for unix sockets */
bind_conf->settings.ux.uid = global.unix_bind.ux.uid;
bind_conf->settings.ux.gid = global.unix_bind.ux.gid;
}
bind_conf = bind_conf_alloc(global.cli_fe, file, line, args[2], xprt_get(XPRT_RAW));
+ if (!bind_conf) {
+ memprintf(err, "'%s %s' : out of memory trying to allocate a bind_conf", args[0], args[1]);
+ return -1;
+ }
bind_conf->level &= ~ACCESS_LVL_MASK;
bind_conf->level |= ACCESS_LVL_OPER; /* default access level */
bind_conf = bind_conf_alloc(cfg_log_forward, file, linenum,
NULL, xprt_get(XPRT_RAW));
+ if (!bind_conf) {
+ ha_alert("parsing [%s:%d] : out of memory error.", file, linenum);
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
+ }
if (!str2receiver(args[1], cfg_log_forward, bind_conf, file, linenum, &errmsg)) {
if (errmsg && *errmsg) {