diff --git a/examples/ucontext-cp.c b/examples/ucontext-cp.c index 0b2a6b5339ff858079e5d17cc91031a660eb2dc8..ea0c934f64ff98f6fa2039085539a173c7efd00a 100644 --- a/examples/ucontext-cp.c +++ b/examples/ucontext-cp.c @@ -28,7 +28,7 @@ typedef struct { struct io_uring *ring; - unsigned char stack_buf[SIGSTKSZ]; + unsigned char *stack_buf; ucontext_t ctx_main, ctx_fnew; } async_context; @@ -115,8 +115,13 @@ static int setup_context(async_context *pctx, struct io_uring *ring) perror("getcontext"); return -1; } - pctx->ctx_fnew.uc_stack.ss_sp = &pctx->stack_buf; - pctx->ctx_fnew.uc_stack.ss_size = sizeof(pctx->stack_buf); + pctx->stack_buf = malloc(SIGSTKSZ); + if (!pctx->stack_buf) { + perror("malloc"); + return -1; + } + pctx->ctx_fnew.uc_stack.ss_sp = pctx->stack_buf; + pctx->ctx_fnew.uc_stack.ss_size = SIGSTKSZ; pctx->ctx_fnew.uc_link = &pctx->ctx_main; return 0; @@ -174,6 +179,7 @@ static void copy_file_wrapper(arguments_bundle *pbundle) free(iov.iov_base); close(pbundle->infd); close(pbundle->outfd); + free(pbundle->pctx->stack_buf); free(pbundle->pctx); free(pbundle);