From 79da0c882f387ab1526c1b6628aee2d524f02d5b Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 9 Nov 2023 07:54:17 -0800 Subject: [PATCH] fix(proxy-wasm) free dispatch calls during resume edge-case Fix a Valgrind memory leak and an unrelated suppression. Dispatch resume invoking on_request_headers for subsequent filters may yield themselves (NGX_AGAIN). In this case, also ensure the dispatch call is destroyed. Fix the suppression for headers-more-nginx-module which can happen with other stacktraces on builtin headers (e.g. Content-Length). --- src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c | 7 +++---- valgrind.suppress | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c b/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c index 41d967a87..38391e9b1 100644 --- a/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c +++ b/src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c @@ -425,6 +425,8 @@ ngx_http_proxy_wasm_dispatch_destroy(ngx_http_proxy_wasm_dispatch_t *call) sock = &call->sock; rctx = call->rctx; + dd("enter"); + ngx_wasm_socket_tcp_destroy(sock); if (call->host.data) { @@ -842,10 +844,7 @@ ngx_http_proxy_wasm_dispatch_resume_handler(ngx_wasm_socket_tcp_t *sock) /* resume current step if unfinished */ rc = ngx_proxy_wasm_resume(pwexec->parent, pwexec->parent->phase, step); - if (rc == NGX_AGAIN) { - goto done; - - } else if (rc != NGX_OK) { + if (rc != NGX_OK && rc != NGX_AGAIN) { goto error; } diff --git a/valgrind.suppress b/valgrind.suppress index c3b011f51..569fe1ec0 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -25,6 +25,7 @@ Memcheck:Cond fun:ngx_http_set_header_helper + ... fun:ngx_http_headers_more_exec_cmd fun:ngx_http_headers_more_filter ...