Fixing memory leak of request parse context.

This commit is contained in:
Max Romanov
2017-09-15 20:30:29 +03:00
parent 0bec14878e
commit 1449e27cb4
3 changed files with 38 additions and 19 deletions

View File

@@ -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;
ctx->mem_pool = nxt_mp_create(1024, 128, 256, 32);
mp = nxt_mp_create(1024, 128, 256, 32);
if (nxt_slow_path(mp == NULL)) {
return NULL;
}
rc = nxt_http_parse_request_init(&ctx->parser, ctx->mem_pool);
ctx = nxt_mp_retain(mp, sizeof(nxt_app_parse_ctx_t));
if (nxt_slow_path(ctx == NULL)) {
nxt_mp_destroy(mp);
return NULL;
}
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;
}