Welcome! Log In Create A New Profile

Advanced

[nginx] Core: fixed memory leak on configuration reload with PCRE2.

Sergey Kandaurov
October 17, 2023 12:24PM
details: https://hg.nginx.org/nginx/rev/533bc2336df4
branches:
changeset: 9166:533bc2336df4
user: Maxim Dounin <mdounin@mdounin.ru>
date: Tue Oct 17 02:39:38 2023 +0300
description:
Core: fixed memory leak on configuration reload with PCRE2.

In ngx_regex_cleanup() allocator wasn't configured when calling
pcre2_compile_context_free() and pcre2_match_data_free(), resulting
in no ngx_free() call and leaked memory. Fix is ensure that allocator
is configured for global allocations, so that ngx_free() is actually
called to free memory.

Additionally, ngx_regex_compile_context was cleared in
ngx_regex_module_init(). It should be either not cleared, so it will
be freed by ngx_regex_cleanup(), or properly freed. Fix is to
not clear it, so ngx_regex_cleanup() will be able to free it.

Reported by ZhenZhong Wu,
https://mailman.nginx.org/pipermail/nginx-devel/2023-September/3Z5FIKUDRN2WBSL3JWTZJ7SXDA6YIWPB.html

diffstat:

src/core/ngx_regex.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)

diffs (31 lines):

diff -r cdda286c0f1b -r 533bc2336df4 src/core/ngx_regex.c
--- a/src/core/ngx_regex.c Tue Oct 10 15:13:39 2023 +0300
+++ b/src/core/ngx_regex.c Tue Oct 17 02:39:38 2023 +0300
@@ -600,6 +600,8 @@ ngx_regex_cleanup(void *data)
* the new cycle, these will be re-allocated.
*/

+ ngx_regex_malloc_init(NULL);
+
if (ngx_regex_compile_context) {
pcre2_compile_context_free(ngx_regex_compile_context);
ngx_regex_compile_context = NULL;
@@ -611,6 +613,8 @@ ngx_regex_cleanup(void *data)
ngx_regex_match_data_size = 0;
}

+ ngx_regex_malloc_done();
+
#endif
}

@@ -706,9 +710,6 @@ ngx_regex_module_init(ngx_cycle_t *cycle
ngx_regex_malloc_done();

ngx_regex_studies = NULL;
-#if (NGX_PCRE2)
- ngx_regex_compile_context = NULL;
-#endif

return NGX_OK;
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Core: fixed memory leak on configuration reload with PCRE2.

Sergey Kandaurov 205 October 17, 2023 12:24PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 58
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready