Commit 3d2efec7 authored by Geoff Simmons's avatar Geoff Simmons

malloc the temp array used for sorting in .compile().

For large sets, workspace could be too small.
parent 1f7815f1
......@@ -355,11 +355,9 @@ VCL_VOID
vmod_set_compile(VRT_CTX, struct VPFX(selector_set) *set)
{
char **members;
unsigned sz;
struct memberidx *idx;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_SELECTOR_SET_MAGIC);
if ((ctx->method & VCL_MET_INIT) == 0) {
......@@ -380,13 +378,11 @@ vmod_set_compile(VRT_CTX, struct VPFX(selector_set) *set)
return;
}
sz = WS_ReserveSize(ctx->ws, sizeof(*idx) * set->nmembers);
if (sz == 0) {
VFAIL(ctx, "%s.compile(): insufficient workspace",
set->vcl_name);
idx = malloc(set->nmembers * sizeof(*idx));
if (idx == NULL) {
VFAIL(ctx, "%s.compile(): out of memory", set->vcl_name);
return;
}
idx = (struct memberidx *)WS_Front(ctx->ws);
for (unsigned i = 0; i < set->nmembers; i++) {
idx[i].n = i;
idx[i].member = members[i];
......@@ -402,11 +398,11 @@ vmod_set_compile(VRT_CTX, struct VPFX(selector_set) *set)
VFAIL(ctx, "%s.compile(\"%s\") failed: %s",
set->vcl_name, members[i],
strerror(errno));
WS_Release(ctx->ws, sz);
free(idx);
return;
}
}
WS_Release(ctx->ws, sz);
free(idx);
errno = 0;
if ((set->hash = PH_Generate(members, set->nmembers)) == NULL) {
......
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