Skip to content

Commit

Permalink
misc(*) remove from ngx_wasm_lua_resolver_resolve call freeing 'rsl…
Browse files Browse the repository at this point in the history
…v_ctx'

Presently the behavior of `ngx_wasm_lua_resolver_resolve` mimics the one
from ngx_resolve_name, which frees its argument 'rslv_ctx' in case of
any errors.

This commit changes `ngx_wasm_lua_resolver_resolve` to not free 'rslv_ctx'
if any errors occur, delegating the responsibility to its caller.

Although it makes `ngx_wasm_lua_resolver_resolve` less consistent with
ngx_resolve_name, this change allows the upcoming logic exposing
`ngx_wasm_lua_resolver_resolve` as a PW foreign-function to allocate
'rslv_ctx' using memory from the pwexec's pool, instead of from malloc.
  • Loading branch information
casimiro committed Nov 15, 2024
1 parent 9238d4a commit 1a324d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/common/lua/ngx_wasm_lua_resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/common/ngx_wasm_socket_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1a324d6

Please sign in to comment.