Fix memory leaks. (#2530)

fixes #2529
This commit is contained in:
Ingo Bürk 2016-11-03 08:18:18 +01:00 committed by Michael Stapelberg
parent 7ad5736875
commit fea0bc1a45
2 changed files with 5 additions and 1 deletions

View File

@ -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;

View File

@ -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;
}