diff --git a/src/common/lua/ngx_wasm_lua_resolver.c b/src/common/lua/ngx_wasm_lua_resolver.c index 3de907eb3..5528c2621 100644 --- a/src/common/lua/ngx_wasm_lua_resolver.c +++ b/src/common/lua/ngx_wasm_lua_resolver.c @@ -207,8 +207,6 @@ ngx_wasm_lua_resolver_resolve(ngx_resolver_ctx_t *rslv_ctx) dd("error exit"); - ngx_free(rslv_ctx); - return NGX_ERROR; } diff --git a/src/common/ngx_wasm_socket_tcp.c b/src/common/ngx_wasm_socket_tcp.c index e39d2151e..f790a27a2 100644 --- a/src/common/ngx_wasm_socket_tcp.c +++ b/src/common/ngx_wasm_socket_tcp.c @@ -405,6 +405,12 @@ ngx_wasm_socket_tcp_connect(ngx_wasm_socket_tcp_t *sock) if (rc != NGX_OK && rc != NGX_AGAIN) { ngx_log_debug0(NGX_LOG_DEBUG_WASM, sock->log, 0, "wasm tcp socket resolver failed before query"); + + /* ngx_resolve_name frees rslv_ctx in case of error */ + if (rctx->pwm_lua_resolver) { + ngx_free(rslv_ctx); + } + return NGX_ERROR; }