Commit de676c22 by Geoff Simmons

Lock initialization of PRIV_CALL-scoped data.

parent 4d9878cb
......@@ -26,6 +26,7 @@
*/
#include <locale.h>
#include <pthread.h>
#include "vmod_pcre2.h"
......@@ -36,6 +37,9 @@
AZ(pcre2_set_##param((ctx), (type)(param))); \
} while(0)
/* Locks initialization of PRIV_CALL-scoped data. */
static pthread_mutex_t call_lock = PTHREAD_MUTEX_INITIALIZER;
void
errmsg(VRT_CTX, const char *fmt, ...)
{
......@@ -245,20 +249,28 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS,
struct match_call *match_opts;
pcre2_match_context *mctx;
AZ(pthread_mutex_lock(&call_lock));
if (priv->priv != NULL) {
/* Someone beat us to it. */
AZ(pthread_mutex_unlock(&call_lock));
CAST_OBJ(match_opts, priv->priv, VMOD_PCRE2_MATCH_CALL_MAGIC);
return match_opts;
}
if (!check_uint32_range(ctx, match_limit, "match_limit", context,
caller))
return NULL;
goto fail;
if (!check_uint32_range(ctx, offset_limit, "offset_limit", context,
caller))
return NULL;
goto fail;
if (!check_uint32_range(ctx, recursion_limit, "recursion_limit",
context, caller))
return NULL;
goto fail;
if ((mctx = pcre2_match_context_create(NULL)) == NULL) {
VERRNOMEM(ctx, "creating match context in %s%s", context,
caller);
return NULL;
goto fail;
}
SET_CTX_PARAM(mctx, match_limit, uint32_t);
SET_CTX_PARAM(mctx, offset_limit, uint32_t);
......@@ -268,7 +280,7 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS,
if (match_opts == NULL) {
VERRNOMEM(ctx, "allocating call-scoped match options in %s%s",
context, caller);
return NULL;
goto fail;
}
match_opts->mctx = mctx;
set_match_flags(&match_opts->match_options, MATCH_SUB_FLAGS_PARAMS);
......@@ -277,5 +289,10 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS,
priv->free = match_call_free;
priv->len = sizeof(*match_opts);
AZ(pthread_mutex_unlock(&call_lock));
return match_opts;
fail:
AZ(pthread_mutex_unlock(&call_lock));
return NULL;
}
......@@ -546,7 +546,6 @@ vmod_match(VRT_CTX, struct vmod_priv *call, struct vmod_priv *task,
}
/* Compile and match options saved in PRIV_CALL scope */
/* XXX need a lock */
if (call->priv != NULL)
CAST_OBJ(match_call, call->priv, VMOD_PCRE2_MATCH_CALL_MAGIC);
else if ((match_call = get_match_opts(ctx, call, MATCH_CTX_PARAMS,
......
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