Skip to content

Commit

Permalink
fix(wasi) do not use instance pool in 'fd_write'
Browse files Browse the repository at this point in the history
Avoid using the long-lived instance pool for a temporary buffer on
fd_write. Since we allocate and deallocate deterministically within the
same function (and to avoid a cross-concern dependency on proxy-wasm to
get pwctx), we simply use ngx_alloc and ngx_free to produce a temporary
buffer.
  • Loading branch information
hishamhm authored and thibaultcha committed Dec 4, 2023
1 parent 4f47e96 commit 8f3fa95
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/wasm/wasi/ngx_wasi_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ ngx_wasi_hfuncs_fd_write(ngx_wavm_instance_t *instance,

/* second pass: build string from iov buffers */

msg_data = ngx_pcalloc(instance->pool, msg_size);
/**
* TODO: replace with a host-pointer-provided pool when possible;
* see https://github.com/Kong/ngx_wasm_module/pull/457
*/
msg_data = ngx_alloc(msg_size, instance->log);
if (msg_data == NULL) {
rets[0] = (wasm_val_t) WASM_I32_VAL(WASI_ERRNO_EFAULT);
return NGX_WAVM_OK;
Expand Down Expand Up @@ -291,6 +295,8 @@ ngx_wasi_hfuncs_fd_write(ngx_wavm_instance_t *instance,
msg_size, msg_data);
}

ngx_free(msg_data);

rets[0] = (wasm_val_t) WASM_I32_VAL(WASI_ERRNO_SUCCESS);
return NGX_WAVM_OK;
}
Expand Down

0 comments on commit 8f3fa95

Please sign in to comment.