summaryrefslogtreecommitdiffstats
path: root/spawn
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2022-04-19 11:34:07 +0300
committerGitHub <noreply@github.com>2022-04-19 11:34:07 +0300
commitbbff41d8435d486f08f360acb56dd6b9cffdd6dd (patch)
tree8e1228d17a5c0b2f23f889d149f9022efa99e4bb /spawn
parent3e1ed14d8e8fd30864ddde6a236467dc4919ed13 (diff)
Allocate buffer memory for uv_write and release in the callback function (#12688)
* Allocate memory needed for uv_write and free it in the callback function * Allocate memory needed for uv_write and free it in the callback function
Diffstat (limited to 'spawn')
-rw-r--r--spawn/spawn_client.c14
-rw-r--r--spawn/spawn_server.c22
2 files changed, 28 insertions, 8 deletions
diff --git a/spawn/spawn_client.c b/spawn/spawn_client.c
index 509c673471..3e37e79676 100644
--- a/spawn/spawn_client.c
+++ b/spawn/spawn_client.c
@@ -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)
@@ -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;
diff --git a/spawn/spawn_server.c b/spawn/spawn_server.c
index 57bcdf99a3..342f2f1459 100644
--- a/spawn/spawn_server.c
+++ b/spawn/spawn_server.c
@@ -71,12 +71,15 @@ 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;
@@ -84,8 +87,13 @@ static void child_waited_async_cb(uv_async_t *async_handle)
(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;
@@ -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