[master] 9f9837fef Avoid creating a priv_task in std.ban() unless we need it
Nils Goroll
nils.goroll at uplex.de
Mon Jan 11 18:36:07 UTC 2021
commit 9f9837fef5a6908df2104cc85de1577f6ecdfcd9
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Jan 11 17:53:33 2021 +0100
Avoid creating a priv_task in std.ban() unless we need it
We only need a new priv_task if we need to log an error.
If one existed before, we need to clear or overwrite the error.
diff --git a/vmod/vmod_std.c b/vmod/vmod_std.c
index 203a621b1..1cf60162c 100644
--- a/vmod/vmod_std.c
+++ b/vmod/vmod_std.c
@@ -322,14 +322,20 @@ vmod_ban(VRT_CTX, VCL_STRING s)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- priv_task = VRT_priv_task(ctx, priv_task_id_ban);
+ r = VRT_ban_string(ctx, s);
+ priv_task = VRT_priv_task_get(ctx, priv_task_id_ban);
+
+ if (r == NULL && priv_task == NULL)
+ return (1);
+
+ if (priv_task == NULL)
+ priv_task = VRT_priv_task(ctx, priv_task_id_ban);
+
if (priv_task == NULL) {
VRT_fail(ctx, "std.ban(): no priv_task (out of workspace?)");
return (0);
}
- r = VRT_ban_string(ctx, s);
-
/*
* TRUST_ME: the ban error is const. We save it in the un-const priv
* pointer, but promise to only ever return it as a (const) VCL_STRING
@@ -347,12 +353,9 @@ vmod_ban_error(VRT_CTX)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- priv_task = VRT_priv_task(ctx, priv_task_id_ban);
- if (priv_task == NULL) {
- VRT_fail(ctx, "std.ban_error():"
- " no priv_task (out of workspace?)");
- return ("no priv_task");
- }
+ priv_task = VRT_priv_task_get(ctx, priv_task_id_ban);
+ if (priv_task == NULL)
+ return ("");
r = priv_task->priv;
if (r == NULL)
More information about the varnish-commit
mailing list