Improve handling of allocation failures

parent e43781b2
...@@ -174,6 +174,7 @@ cluster_task_param_l(VRT_CTX, struct vmod_cluster_cluster *vc, ...@@ -174,6 +174,7 @@ cluster_task_param_l(VRT_CTX, struct vmod_cluster_cluster *vc,
nblack = RUP2(nblack, 2); nblack = RUP2(nblack, 2);
if (ctx->method & VCL_MET_INIT) { if (ctx->method & VCL_MET_INIT) {
p = realloc(p, param_sz(p, nblack)); p = realloc(p, param_sz(p, nblack));
AN(p);
vc->param = p; vc->param = p;
} else { } else {
AN(o); AN(o);
...@@ -186,6 +187,7 @@ cluster_task_param_l(VRT_CTX, struct vmod_cluster_cluster *vc, ...@@ -186,6 +187,7 @@ cluster_task_param_l(VRT_CTX, struct vmod_cluster_cluster *vc,
task->priv = p; task->priv = p;
} }
AN(p);
if (o == NULL) if (o == NULL)
INIT_OBJ(p, VMOD_CLUSTER_CLUSTER_PARAM_MAGIC); INIT_OBJ(p, VMOD_CLUSTER_CLUSTER_PARAM_MAGIC);
...@@ -398,6 +400,8 @@ vmod_cluster_get_cluster(VRT_CTX, struct vmod_cluster_cluster *vc) ...@@ -398,6 +400,8 @@ vmod_cluster_get_cluster(VRT_CTX, struct vmod_cluster_cluster *vc)
return; \ return; \
\ \
pl = cluster_task_param_l(ctx, vc, 0, NULL); \ pl = cluster_task_param_l(ctx, vc, 0, NULL); \
if (pl == NULL) \
return; \
pl->att = (val) pl->att = (val)
/* get a simple parameter attribute */ /* get a simple parameter attribute */
...@@ -409,6 +413,7 @@ vmod_cluster_get_cluster(VRT_CTX, struct vmod_cluster_cluster *vc) ...@@ -409,6 +413,7 @@ vmod_cluster_get_cluster(VRT_CTX, struct vmod_cluster_cluster *vc)
CHECK_OBJ_NOTNULL(vc, VMOD_CLUSTER_CLUSTER_MAGIC); \ CHECK_OBJ_NOTNULL(vc, VMOD_CLUSTER_CLUSTER_MAGIC); \
\ \
pr = cluster_task_param_r(ctx, vc); \ pr = cluster_task_param_r(ctx, vc); \
AN(pr); \
\ \
return (pr->att) return (pr->att)
...@@ -527,20 +532,26 @@ cluster_update_by_args(VRT_CTX, struct vmod_cluster_cluster *vc, ...@@ -527,20 +532,26 @@ cluster_update_by_args(VRT_CTX, struct vmod_cluster_cluster *vc,
if (arg->valid_deny && arg->deny != NULL && if (arg->valid_deny && arg->deny != NULL &&
! cluster_denied(pr, arg->deny)) { ! cluster_denied(pr, arg->deny)) {
pr = pl = cluster_task_param_l(ctx, vc, ++nblack, spc);
if (pl == NULL) if (pl == NULL)
pr = pl = cluster_task_param_l(ctx, vc, return (NULL);
++nblack, spc);
cluster_deny(ctx, pl, arg->deny); cluster_deny(ctx, pl, arg->deny);
} }
AN(pr);
if (arg->valid_real && pr->real != arg->real) { if (arg->valid_real && pr->real != arg->real) {
if (pl == NULL) if (pl == NULL)
pr = pl = cluster_task_param_l(ctx, vc, nblack, spc); pr = pl = cluster_task_param_l(ctx, vc, nblack, spc);
if (pl == NULL)
return (NULL);
pl->real = arg->real; pl->real = arg->real;
} }
AN(pr);
if (arg->valid_uncacheable_direct && if (arg->valid_uncacheable_direct &&
pr->uncacheable_direct != arg->uncacheable_direct) { pr->uncacheable_direct != arg->uncacheable_direct) {
if (pl == NULL) if (pl == NULL)
pr = pl = cluster_task_param_l(ctx, vc, nblack, spc); pr = pl = cluster_task_param_l(ctx, vc, nblack, spc);
if (pl == NULL)
return (NULL);
pl->uncacheable_direct = arg->uncacheable_direct; pl->uncacheable_direct = arg->uncacheable_direct;
} }
return (pr); return (pr);
...@@ -585,6 +596,8 @@ cluster_choose(VRT_CTX, ...@@ -585,6 +596,8 @@ cluster_choose(VRT_CTX,
spc = pstk; spc = pstk;
pr = cluster_update_by_args(ctx, vc, pr, arg, spc); pr = cluster_update_by_args(ctx, vc, pr, arg, spc);
if (pr == NULL)
return (NULL);
if (resolve == LAZY) if (resolve == LAZY)
return (vc->dir); return (vc->dir);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment