Skip to content

Commit 720bd5d

Browse files
skyeveragentzh
authored andcommitted
bugfix: the fake requests/connections might leak when memory allocations fail.
as discussed in openresty#1098. Signed-off-by: skyever <i@kill9.cn> Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent c372e1c commit 720bd5d

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/ngx_http_lua_ssl_certby.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ ngx_http_lua_ssl_cert_by_chunk(lua_State *L, ngx_http_request_t *r)
464464
if (ctx == NULL) {
465465
ctx = ngx_http_lua_create_ctx(r);
466466
if (ctx == NULL) {
467-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
467+
rc = NGX_ERROR;
468+
ngx_http_lua_finalize_request(r, rc);
469+
return rc;
468470
}
469471

470472
} else {
@@ -481,7 +483,9 @@ ngx_http_lua_ssl_cert_by_chunk(lua_State *L, ngx_http_request_t *r)
481483
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
482484
"lua: failed to create new coroutine to handle request");
483485

484-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
486+
rc = NGX_ERROR;
487+
ngx_http_lua_finalize_request(r, rc);
488+
return rc;
485489
}
486490

487491
/* move code closure to new coroutine */
@@ -505,7 +509,9 @@ ngx_http_lua_ssl_cert_by_chunk(lua_State *L, ngx_http_request_t *r)
505509
if (ctx->cleanup == NULL) {
506510
cln = ngx_http_cleanup_add(r, 0);
507511
if (cln == NULL) {
508-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
512+
rc = NGX_ERROR;
513+
ngx_http_lua_finalize_request(r, rc);
514+
return rc;
509515
}
510516

511517
cln->handler = ngx_http_lua_request_cleanup_handler;

src/ngx_http_lua_ssl_session_fetchby.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,9 @@ ngx_http_lua_ssl_sess_fetch_by_chunk(lua_State *L, ngx_http_request_t *r)
468468
if (ctx == NULL) {
469469
ctx = ngx_http_lua_create_ctx(r);
470470
if (ctx == NULL) {
471-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
471+
rc = NGX_ERROR;
472+
ngx_http_lua_finalize_request(r, rc);
473+
return rc;
472474
}
473475

474476
} else {
@@ -485,7 +487,9 @@ ngx_http_lua_ssl_sess_fetch_by_chunk(lua_State *L, ngx_http_request_t *r)
485487
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
486488
"lua: failed to create new coroutine to handle request");
487489

488-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
490+
rc = NGX_ERROR;
491+
ngx_http_lua_finalize_request(r, rc);
492+
return rc;
489493
}
490494

491495
/* move code closure to new coroutine */
@@ -509,7 +513,9 @@ ngx_http_lua_ssl_sess_fetch_by_chunk(lua_State *L, ngx_http_request_t *r)
509513
if (ctx->cleanup == NULL) {
510514
cln = ngx_http_cleanup_add(r, 0);
511515
if (cln == NULL) {
512-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
516+
rc = NGX_ERROR;
517+
ngx_http_lua_finalize_request(r, rc);
518+
return rc;
513519
}
514520

515521
cln->handler = ngx_http_lua_request_cleanup_handler;

src/ngx_http_lua_ssl_session_storeby.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ ngx_http_lua_ssl_sess_store_by_chunk(lua_State *L, ngx_http_request_t *r)
351351
if (ctx == NULL) {
352352
ctx = ngx_http_lua_create_ctx(r);
353353
if (ctx == NULL) {
354-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
354+
rc = NGX_ERROR;
355+
ngx_http_lua_finalize_request(r, rc);
356+
return rc;
355357
}
356358

357359
} else {

0 commit comments

Comments
 (0)