]>
Commit | Line | Data |
---|---|---|
6dafd76e AM |
1 | From 284a0c73771e3a2c57af6e74d96d9a6878b2e7b4 Mon Sep 17 00:00:00 2001 |
2 | From: Maxim Dounin <mdounin@mdounin.ru> | |
3 | Date: Tue, 17 Oct 2023 02:39:38 +0300 | |
4 | Subject: [PATCH] Core: fixed memory leak on configuration reload with PCRE2. | |
5 | ||
6 | In ngx_regex_cleanup() allocator wasn't configured when calling | |
7 | pcre2_compile_context_free() and pcre2_match_data_free(), resulting | |
8 | in no ngx_free() call and leaked memory. Fix is ensure that allocator | |
9 | is configured for global allocations, so that ngx_free() is actually | |
10 | called to free memory. | |
11 | ||
12 | Additionally, ngx_regex_compile_context was cleared in | |
13 | ngx_regex_module_init(). It should be either not cleared, so it will | |
14 | be freed by ngx_regex_cleanup(), or properly freed. Fix is to | |
15 | not clear it, so ngx_regex_cleanup() will be able to free it. | |
16 | ||
17 | Reported by ZhenZhong Wu, | |
18 | https://mailman.nginx.org/pipermail/nginx-devel/2023-September/3Z5FIKUDRN2WBSL3JWTZJ7SXDA6YIWPB.html | |
19 | --- | |
20 | src/core/ngx_regex.c | 7 ++++--- | |
21 | 1 file changed, 4 insertions(+), 3 deletions(-) | |
22 | ||
23 | diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c | |
24 | index 91381f4994..5b13c5db38 100644 | |
25 | --- a/src/core/ngx_regex.c | |
26 | +++ b/src/core/ngx_regex.c | |
27 | @@ -600,6 +600,8 @@ ngx_regex_cleanup(void *data) | |
28 | * the new cycle, these will be re-allocated. | |
29 | */ | |
30 | ||
31 | + ngx_regex_malloc_init(NULL); | |
32 | + | |
33 | if (ngx_regex_compile_context) { | |
34 | pcre2_compile_context_free(ngx_regex_compile_context); | |
35 | ngx_regex_compile_context = NULL; | |
36 | @@ -611,6 +613,8 @@ ngx_regex_cleanup(void *data) | |
37 | ngx_regex_match_data_size = 0; | |
38 | } | |
39 | ||
40 | + ngx_regex_malloc_done(); | |
41 | + | |
42 | #endif | |
43 | } | |
44 | ||
45 | @@ -706,9 +710,6 @@ ngx_regex_module_init(ngx_cycle_t *cycle) | |
46 | ngx_regex_malloc_done(); | |
47 | ||
48 | ngx_regex_studies = NULL; | |
49 | -#if (NGX_PCRE2) | |
50 | - ngx_regex_compile_context = NULL; | |
51 | -#endif | |
52 | ||
53 | return NGX_OK; | |
54 | } |