aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_regex.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2012-01-30 12:53:57 +0000
committerValentin Bartenev <vbart@nginx.com>2012-01-30 12:53:57 +0000
commitfbf7a0a48adce49480ebb29bc7a6dc957d240863 (patch)
treee35532953f85a8b6c14bd8bf5ce4675c7c1c805a /src/core/ngx_regex.c
parent3feafa765f5c065ec2921ef92c4c32c2dea4736c (diff)
downloadnginx-fbf7a0a48adce49480ebb29bc7a6dc957d240863.tar.gz
nginx-fbf7a0a48adce49480ebb29bc7a6dc957d240863.zip
Fixed memory leak on HUP signal when PCRE JIT was used.
The PCRE JIT compiler uses mmap to allocate memory for its executable codes, so we have to explicitly call the pcre_free_study() function to free this memory.
Diffstat (limited to 'src/core/ngx_regex.c')
-rw-r--r--src/core/ngx_regex.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c
index a7137fe4e..677f862bf 100644
--- a/src/core/ngx_regex.c
+++ b/src/core/ngx_regex.c
@@ -16,6 +16,9 @@ typedef struct {
static void * ngx_libc_cdecl ngx_regex_malloc(size_t size);
static void ngx_libc_cdecl ngx_regex_free(void *p);
+#if (NGX_HAVE_PCRE_JIT)
+static void ngx_pcre_free_studies(void *data);
+#endif
static ngx_int_t ngx_regex_module_init(ngx_cycle_t *cycle);
@@ -274,6 +277,41 @@ ngx_regex_free(void *p)
}
+#if (NGX_HAVE_PCRE_JIT)
+
+static void
+ngx_pcre_free_studies(void *data)
+{
+ ngx_list_t *studies = data;
+
+ ngx_uint_t i;
+ ngx_list_part_t *part;
+ ngx_regex_elt_t *elts;
+
+ part = &studies->part;
+ elts = part->elts;
+
+ for (i = 0 ; /* void */ ; i++) {
+
+ if (i >= part->nelts) {
+ if (part->next == NULL) {
+ break;
+ }
+
+ part = part->next;
+ elts = part->elts;
+ i = 0;
+ }
+
+ if (elts[i].regex->extra != NULL) {
+ pcre_free_study(elts[i].regex->extra);
+ }
+ }
+}
+
+#endif
+
+
static ngx_int_t
ngx_regex_module_init(ngx_cycle_t *cycle)
{
@@ -287,12 +325,27 @@ ngx_regex_module_init(ngx_cycle_t *cycle)
#if (NGX_HAVE_PCRE_JIT)
{
- ngx_regex_conf_t *rcf;
+ ngx_regex_conf_t *rcf;
+ ngx_pool_cleanup_t *cln;
rcf = (ngx_regex_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_regex_module);
if (rcf->pcre_jit) {
opt = PCRE_STUDY_JIT_COMPILE;
+
+ /*
+ * The PCRE JIT compiler uses mmap for its executable codes, so we
+ * have to explicitly call the pcre_free_study() function to free
+ * this memory.
+ */
+
+ cln = ngx_pool_cleanup_add(cycle->pool, 0);
+ if (cln == NULL) {
+ return NGX_ERROR;
+ }
+
+ cln->handler = ngx_pcre_free_studies;
+ cln->data = ngx_pcre_studies;
}
}
#endif