From fea0bc1a454788a0a7db563ffb307bf8896fc0df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ingo=20B=C3=BCrk?= Date: Thu, 3 Nov 2016 08:18:18 +0100 Subject: [PATCH] Fix memory leaks. (#2530) fixes #2529 --- i3-msg/main.c | 3 ++- src/main.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/i3-msg/main.c b/i3-msg/main.c index 51612459..915d326f 100644 --- a/i3-msg/main.c +++ b/i3-msg/main.c @@ -206,7 +206,7 @@ int main(int argc, char *argv[]) { } if (!payload) - payload = ""; + payload = sstrdup(""); int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0); if (sockfd == -1) @@ -221,6 +221,7 @@ int main(int argc, char *argv[]) { if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t *)payload) == -1) err(EXIT_FAILURE, "IPC: write()"); + free(payload); if (quiet) return 0; diff --git a/src/main.c b/src/main.c index 4d9fd5a5..4737175b 100644 --- a/src/main.c +++ b/src/main.c @@ -403,12 +403,14 @@ int main(int argc, char *argv[]) { memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_LOCAL; strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1); + FREE(socket_path); if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) err(EXIT_FAILURE, "Could not connect to i3"); if (ipc_send_message(sockfd, strlen(payload), I3_IPC_MESSAGE_TYPE_COMMAND, (uint8_t *)payload) == -1) err(EXIT_FAILURE, "IPC: write()"); + FREE(payload); uint32_t reply_length; uint32_t reply_type; @@ -422,6 +424,7 @@ int main(int argc, char *argv[]) { if (reply_type != I3_IPC_MESSAGE_TYPE_COMMAND) errx(EXIT_FAILURE, "IPC: received reply of type %d but expected %d (COMMAND)", reply_type, I3_IPC_MESSAGE_TYPE_COMMAND); printf("%.*s\n", reply_length, reply); + FREE(reply); return 0; } -- 2.39.5