@cryptotaxi247 / netdata-1 / commits / 2f97b643f

Allocate buffer and release on callback when executing agent CLI commands (#12540)

* Allocate buffer and release on callback * Allocate MAX_COMMAND_LENGTH for now. Proper allocation depending on the size of the message will be addressed in a future PR

Stelios Fragkakis committed Mar 28, 2022 at 20:09 UTC 2f97b643ff8606065f90f19f8fdf8c5db7cae13f
1 file changed +3 -1
daemon/commands.c
+3 -1
@@ -387,6 +387,7 @@ static void pipe_write_cb(uv_write_t* req, int status)
387
388 uv_close((uv_handle_t *)client, pipe_close_cb);
389 --clients;
390 + freez(client->data);
391 info("Command Clients = %u\n", clients);
392 }
393
@@ -411,7 +412,7 @@ static inline void add_string_to_command_reply(char *reply_string, unsigned *rep
412 static void send_command_reply(struct command_context *cmd_ctx, cmd_status_t status, char *message)
413 {
414 int ret;
414 - char reply_string[MAX_COMMAND_LENGTH] = {'\0', };
415 + char *reply_string = mallocz(MAX_COMMAND_LENGTH);
416 char exit_status_string[MAX_EXIT_STATUS_LENGTH + 1] = {'\0', };
417 unsigned reply_string_size = 0;
418 uv_buf_t write_buf;
@@ -428,6 +429,7 @@ static void send_command_reply(struct command_context *cmd_ctx, cmd_status_t sta
429 }
430
431 cmd_ctx->write_req.data = client;
432 + client->data = reply_string;
433 write_buf.base = reply_string;
434 write_buf.len = reply_string_size;
435 ret = uv_write(&cmd_ctx->write_req, (uv_stream_t *)client, &write_buf, 1, pipe_write_cb);