Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate buffer memory for uv_write and release in the callback function #12688

Merged
merged 2 commits into from Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions spawn/spawn_client.c
Expand Up @@ -21,7 +21,10 @@ static void after_pipe_write(uv_write_t* req, int status)
#ifdef SPAWN_DEBUG
info("CLIENT %s called status=%d", __func__, status);
#endif
freez(req->data);
void **data = req->data;
freez(data[0]);
freez(data[1]);
freez(data);
}

static void client_parse_spawn_protocol(unsigned source_len, char *source)
Expand Down Expand Up @@ -135,11 +138,16 @@ static void on_read_alloc(uv_handle_t* handle,
static void spawn_process_cmd(struct spawn_cmd_info *cmdinfo)
{
int ret;
uv_buf_t writebuf[3];
uv_buf_t *writebuf;
struct write_context *write_ctx;

void **data = callocz(2, sizeof(void *));
writebuf = callocz(3, sizeof(uv_buf_t));
write_ctx = callocz(1, sizeof(*write_ctx));
write_ctx->write_req.data = write_ctx;

data[0] = write_ctx;
data[1] = writebuf;
write_ctx->write_req.data = data;

uv_mutex_lock(&cmdinfo->mutex);
cmdinfo->flags |= SPAWN_CMD_PROCESSED;
Expand Down
22 changes: 17 additions & 5 deletions spawn/spawn_server.c
Expand Up @@ -71,21 +71,29 @@ static void after_pipe_write(uv_write_t *req, int status)
#ifdef SPAWN_DEBUG
fprintf(stderr, "SERVER %s called status=%d\n", __func__, status);
#endif
freez(req->data);
void **data = req->data;
freez(data[0]);
freez(data[1]);
freez(data);
}

static void child_waited_async_cb(uv_async_t *async_handle)
{
uv_buf_t writebuf[2];
uv_buf_t *writebuf;
int ret;
struct spawn_execution_info *exec_info;
struct write_context *write_ctx;

(void)async_handle;
while (NULL != (exec_info = dequeue_child_waited_list())) {
write_ctx = mallocz(sizeof(*write_ctx));
write_ctx->write_req.data = write_ctx;

void **data = callocz(2, sizeof(void *));
writebuf = callocz(2, sizeof(uv_buf_t));

data[0] = write_ctx;
data[1] = writebuf;
write_ctx->write_req.data = data;

write_ctx->header.opcode = SPAWN_PROT_CMD_EXIT_STATUS;
write_ctx->header.handle = exec_info->handle;
Expand Down Expand Up @@ -151,14 +159,18 @@ static void wait_children(void *arg)

void spawn_protocol_execute_command(void *handle, char *command_to_run, uint16_t command_length)
{
uv_buf_t writebuf[2];
uv_buf_t *writebuf;
int ret;
avl_t *avl_ret;
struct spawn_execution_info *exec_info;
struct write_context *write_ctx;

write_ctx = mallocz(sizeof(*write_ctx));
write_ctx->write_req.data = write_ctx;
void **data = callocz(2, sizeof(void *));
writebuf = callocz(2, sizeof(uv_buf_t));
data[0] = write_ctx;
data[1] = writebuf;
write_ctx->write_req.data = data;

command_to_run[command_length] = '\0';
#ifdef SPAWN_DEBUG
Expand Down