summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_application.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2017-09-15 20:30:29 +0300
committerMax Romanov <max.romanov@nginx.com>2017-09-15 20:30:29 +0300
commit1449e27cb42a5b3ca2d2106a39fee3f1d54a340e (patch)
treea44a1ef5cb5cbf33424ab8b15085331a1d80b3ae /src/nxt_application.c
parent0bec14878e99de280046e1d1b1a0195e5478c808 (diff)
downloadunit-1449e27cb42a5b3ca2d2106a39fee3f1d54a340e.tar.gz
unit-1449e27cb42a5b3ca2d2106a39fee3f1d54a340e.tar.bz2
Fixing memory leak of request parse context.
Diffstat (limited to 'src/nxt_application.c')
-rw-r--r--src/nxt_application.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/nxt_application.c b/src/nxt_application.c
index d795c230..30b9d1fa 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -772,21 +772,39 @@ static nxt_http_fields_hash_entry_t nxt_app_request_fields[] = {
};
-nxt_int_t
-nxt_app_http_req_init(nxt_task_t *task, nxt_app_parse_ctx_t *ctx)
+nxt_app_parse_ctx_t *
+nxt_app_http_req_init(nxt_task_t *task)
{
- nxt_int_t rc;
+ nxt_mp_t *mp;
+ nxt_int_t rc;
+ nxt_app_parse_ctx_t *ctx;
+
+ mp = nxt_mp_create(1024, 128, 256, 32);
+ if (nxt_slow_path(mp == NULL)) {
+ return NULL;
+ }
+
+ ctx = nxt_mp_retain(mp, sizeof(nxt_app_parse_ctx_t));
+ if (nxt_slow_path(ctx == NULL)) {
+ nxt_mp_destroy(mp);
- ctx->mem_pool = nxt_mp_create(1024, 128, 256, 32);
+ return NULL;
+ }
- rc = nxt_http_parse_request_init(&ctx->parser, ctx->mem_pool);
+ nxt_memzero(ctx, sizeof(nxt_app_parse_ctx_t));
+
+ ctx->mem_pool = mp;
+
+ rc = nxt_http_parse_request_init(&ctx->parser, mp);
if (nxt_slow_path(rc != NXT_OK)) {
- return rc;
+ nxt_mp_release(mp, ctx);
+
+ return NULL;
}
ctx->parser.fields_hash = nxt_app_request_fields_hash;
- return NXT_OK;
+ return ctx;
}
@@ -879,7 +897,7 @@ nxt_app_http_req_body_read(nxt_task_t *task, nxt_app_parse_ctx_t *ctx,
nxt_int_t
nxt_app_http_req_done(nxt_task_t *task, nxt_app_parse_ctx_t *ctx)
{
- nxt_mp_destroy(ctx->mem_pool);
+ nxt_mp_release(ctx->mem_pool, ctx);
return NXT_OK;
}