From 90a51a7ed7521732f6656849193621ed8b3f2f89 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Wed, 8 Jul 2020 01:08:00 +0200 Subject: [PATCH] buffers don't require malloc anymore --- src/communication.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/communication.c b/src/communication.c index 9262a09..9f3d95f 100644 --- a/src/communication.c +++ b/src/communication.c @@ -190,16 +190,15 @@ struct ipc_error ipc_read (const struct ipc_ctx *ctx, uint32_t index, struct ipc struct ipc_error ipc_write_fd (int fd, const struct ipc_message *m) { - char *buf = NULL; size_t msize = 0; - ipc_message_format_write (m, &buf, &msize); + SECURE_BUFFER_DECLARATION (char, buf, IPC_MAX_MESSAGE_SIZE); + char *pbuf = buf; + + ipc_message_format_write (m, &pbuf, &msize); size_t nbytes_sent = 0; - TEST_IPC_RETURN_ON_ERROR_FREE (usock_send (fd, buf, msize, &nbytes_sent), buf); + TEST_IPC_RETURN_ON_ERROR (usock_send (fd, buf, msize, &nbytes_sent)); - if (buf != NULL) { - free (buf); - } // what was sent != what should have been sent T_R ((nbytes_sent != msize), IPC_ERROR_WRITE_FD__NOT_ENOUGH_DATA);