comparison src/core/ngx_regex.c @ 660:d0f7a625f27c NGINX_1_1_14

nginx 1.1.14 *) Feature: multiple "limit_req" limits may be used simultaneously. *) Bugfix: in error handling while connecting to a backend. Thanks to Piotr Sikora. *) Bugfix: in AIO error handling on FreeBSD. *) Bugfix: in the OpenSSL library initialization. *) Bugfix: the "proxy_redirect" directives might not be correctly inherited. *) Bugfix: memory leak during reconfiguration if the "pcre_jit" directive was used.
author Igor Sysoev <http://sysoev.ru>
date Mon, 30 Jan 2012 00:00:00 +0400
parents 9d21dad0b5a1
children bfa81a0490a2
comparison
equal deleted inserted replaced
659:d48f991d7bd0 660:d0f7a625f27c
1 1
2 /* 2 /*
3 * Copyright (C) Igor Sysoev 3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
4 */ 5 */
5 6
6 7
7 #include <ngx_config.h> 8 #include <ngx_config.h>
8 #include <ngx_core.h> 9 #include <ngx_core.h>
13 } ngx_regex_conf_t; 14 } ngx_regex_conf_t;
14 15
15 16
16 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size); 17 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size);
17 static void ngx_libc_cdecl ngx_regex_free(void *p); 18 static void ngx_libc_cdecl ngx_regex_free(void *p);
19 #if (NGX_HAVE_PCRE_JIT)
20 static void ngx_pcre_free_studies(void *data);
21 #endif
18 22
19 static ngx_int_t ngx_regex_module_init(ngx_cycle_t *cycle); 23 static ngx_int_t ngx_regex_module_init(ngx_cycle_t *cycle);
20 24
21 static void *ngx_regex_create_conf(ngx_cycle_t *cycle); 25 static void *ngx_regex_create_conf(ngx_cycle_t *cycle);
22 static char *ngx_regex_init_conf(ngx_cycle_t *cycle, void *conf); 26 static char *ngx_regex_init_conf(ngx_cycle_t *cycle, void *conf);
271 { 275 {
272 return; 276 return;
273 } 277 }
274 278
275 279
280 #if (NGX_HAVE_PCRE_JIT)
281
282 static void
283 ngx_pcre_free_studies(void *data)
284 {
285 ngx_list_t *studies = data;
286
287 ngx_uint_t i;
288 ngx_list_part_t *part;
289 ngx_regex_elt_t *elts;
290
291 part = &studies->part;
292 elts = part->elts;
293
294 for (i = 0 ; /* void */ ; i++) {
295
296 if (i >= part->nelts) {
297 if (part->next == NULL) {
298 break;
299 }
300
301 part = part->next;
302 elts = part->elts;
303 i = 0;
304 }
305
306 if (elts[i].regex->extra != NULL) {
307 pcre_free_study(elts[i].regex->extra);
308 }
309 }
310 }
311
312 #endif
313
314
276 static ngx_int_t 315 static ngx_int_t
277 ngx_regex_module_init(ngx_cycle_t *cycle) 316 ngx_regex_module_init(ngx_cycle_t *cycle)
278 { 317 {
279 int opt; 318 int opt;
280 const char *errstr; 319 const char *errstr;
284 323
285 opt = 0; 324 opt = 0;
286 325
287 #if (NGX_HAVE_PCRE_JIT) 326 #if (NGX_HAVE_PCRE_JIT)
288 { 327 {
289 ngx_regex_conf_t *rcf; 328 ngx_regex_conf_t *rcf;
329 ngx_pool_cleanup_t *cln;
290 330
291 rcf = (ngx_regex_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_regex_module); 331 rcf = (ngx_regex_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_regex_module);
292 332
293 if (rcf->pcre_jit) { 333 if (rcf->pcre_jit) {
294 opt = PCRE_STUDY_JIT_COMPILE; 334 opt = PCRE_STUDY_JIT_COMPILE;
335
336 /*
337 * The PCRE JIT compiler uses mmap for its executable codes, so we
338 * have to explicitly call the pcre_free_study() function to free
339 * this memory.
340 */
341
342 cln = ngx_pool_cleanup_add(cycle->pool, 0);
343 if (cln == NULL) {
344 return NGX_ERROR;
345 }
346
347 cln->handler = ngx_pcre_free_studies;
348 cln->data = ngx_pcre_studies;
295 } 349 }
296 } 350 }
297 #endif 351 #endif
298 352
299 ngx_regex_malloc_init(cycle->pool); 353 ngx_regex_malloc_init(cycle->pool);
400 *fp = 0; 454 *fp = 0;
401 } 455 }
402 } 456 }
403 #else 457 #else
404 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, 458 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
405 "nginx was build without PCRE JIT support"); 459 "nginx was built without PCRE JIT support");
406 *fp = 0; 460 *fp = 0;
407 #endif 461 #endif
408 462
409 return NGX_CONF_OK; 463 return NGX_CONF_OK;
410 } 464 }