Skip to content

Commit 9279612

Browse files
committed
bugfix: use of lua-resty-core's ngx.re API in init_by_lua* might lead to memory issues during nginx HUP reload when no lua_shared_dict directives are used and the regex cache is enabled.
1 parent 012f316 commit 9279612

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/ngx_http_lua_regex.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,8 @@ ngx_http_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
21992199
goto error;
22002200
}
22012201

2202+
pool->log = (ngx_log_t *) &ngx_cycle->new_log;
2203+
22022204
re = ngx_palloc(pool, sizeof(ngx_http_lua_regex_t));
22032205
if (re == NULL) {
22042206
ngx_destroy_pool(pool);

t/124-init-worker.t

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,9 @@ ok
768768
#lua_shared_dict dummy 500k;
769769
770770
init_by_lua_block {
771-
-- require "resty.core.regex"
772-
-- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
771+
require "resty.core.regex"
772+
assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
773+
assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
773774
}
774775
775776
--- config
@@ -801,8 +802,9 @@ start privileged agent process
801802
lua_shared_dict dummy 500k;
802803
803804
init_by_lua_block {
804-
-- require "resty.core.regex"
805-
-- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
805+
require "resty.core.regex"
806+
assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
807+
assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
806808
}
807809
808810
--- config
@@ -835,8 +837,9 @@ start privileged agent process
835837
836838
init_by_lua_block {
837839
assert(require "ngx.process".enable_privileged_agent())
838-
-- require "resty.core.regex"
839-
-- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
840+
require "resty.core.regex"
841+
assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
842+
assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
840843
}
841844
842845
--- config
@@ -870,8 +873,9 @@ qr/start privileged agent process \d+/
870873
871874
init_by_lua_block {
872875
assert(require "ngx.process".enable_privileged_agent())
873-
-- require "resty.core.regex"
874-
-- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
876+
require "resty.core.regex"
877+
assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
878+
assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
875879
}
876880
877881
init_worker_by_lua_block {
@@ -909,8 +913,9 @@ qr/lua close the global Lua VM ([0-9A-F]+)$/,
909913
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
910914
911915
init_by_lua_block {
912-
-- require "resty.core.regex"
913-
-- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
916+
require "resty.core.regex"
917+
assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
918+
assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
914919
}
915920
916921
init_worker_by_lua_block {

0 commit comments

Comments
 (0)