Skip to content

Commit

Permalink
Merge pull request owasp-modsecurity#139 from chaizhenhua/remotes/trunk
Browse files Browse the repository at this point in the history
Fixed fd leackage after reload
  • Loading branch information
brenosilva committed Sep 4, 2013
2 parents 414033a + e0993fc commit 10fd40f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions nginx/modsecurity/ngx_http_modsecurity.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static char *ngx_http_modsecurity_enable(ngx_conf_t *cf, ngx_command_t *cmd, voi

static ngx_http_modsecurity_ctx_t * ngx_http_modsecurity_create_ctx(ngx_http_request_t *r);
static int ngx_http_modsecurity_drop_action(request_rec *r);
static void ngx_http_modsecurity_terminate(ngx_cycle_t *cycle);
static void ngx_http_modsecurity_terminate(void *data);
static void ngx_http_modsecurity_cleanup(void *data);

static int ngx_http_modsecurity_save_headers_in_visitor(void *data, const char *key, const char *value);
Expand Down Expand Up @@ -115,8 +115,8 @@ ngx_module_t ngx_http_modsecurity = {
ngx_http_modsecurity_init_process, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
ngx_http_modsecurity_terminate, /* exit process */
ngx_http_modsecurity_terminate, /* exit master */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};

Expand Down Expand Up @@ -886,6 +886,15 @@ static server_rec *modsec_server = NULL;
static ngx_int_t
ngx_http_modsecurity_preconfiguration(ngx_conf_t *cf)
{
ngx_pool_cleanup_t *cln;

cln = ngx_pool_cleanup_add(cf->pool, 0);
if (cln == NULL) {
return NGX_ERROR;
}

cln->handler = ngx_http_modsecurity_terminate;

/* XXX: temporary hack, nginx uses pcre as well and hijacks these two */
pcre_malloc = modsec_pcre_malloc;
pcre_free = modsec_pcre_free;
Expand Down Expand Up @@ -913,7 +922,7 @@ ngx_http_modsecurity_preconfiguration(ngx_conf_t *cf)


static void
ngx_http_modsecurity_terminate(ngx_cycle_t *cycle)
ngx_http_modsecurity_terminate(void *data)
{
if (modsec_server) {
modsecTerminate();
Expand Down

0 comments on commit 10fd40f

Please sign in to comment.