diff options
Diffstat (limited to 'common/ipc-client.c')
-rw-r--r-- | common/ipc-client.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c index 3515ef0a..13fd8a05 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c | |||
@@ -61,7 +61,7 @@ int ipc_open_socket(const char *socket_path) { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | struct ipc_response *ipc_recv_response(int socketfd) { | 63 | struct ipc_response *ipc_recv_response(int socketfd) { |
64 | char data[ipc_header_size]; | 64 | char *data = malloc(sizeof(char) * ipc_header_size); |
65 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | 65 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); |
66 | 66 | ||
67 | size_t total = 0; | 67 | size_t total = 0; |
@@ -81,6 +81,8 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
81 | total = 0; | 81 | total = 0; |
82 | memcpy(&response->size, &data32[0], sizeof(data32[0])); | 82 | memcpy(&response->size, &data32[0], sizeof(data32[0])); |
83 | memcpy(&response->type, &data32[1], sizeof(data32[1])); | 83 | memcpy(&response->type, &data32[1], sizeof(data32[1])); |
84 | free(data); | ||
85 | |||
84 | char *payload = malloc(response->size + 1); | 86 | char *payload = malloc(response->size + 1); |
85 | if (!payload) { | 87 | if (!payload) { |
86 | goto error_2; | 88 | goto error_2; |
@@ -99,6 +101,7 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
99 | return response; | 101 | return response; |
100 | error_2: | 102 | error_2: |
101 | free(response); | 103 | free(response); |
104 | free(payload); | ||
102 | error_1: | 105 | error_1: |
103 | wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response"); | 106 | wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response"); |
104 | return NULL; | 107 | return NULL; |
@@ -110,7 +113,7 @@ void free_ipc_response(struct ipc_response *response) { | |||
110 | } | 113 | } |
111 | 114 | ||
112 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { | 115 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { |
113 | char data[ipc_header_size]; | 116 | char *data = malloc(sizeof(char) * ipc_header_size); |
114 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | 117 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); |
115 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | 118 | memcpy(data, ipc_magic, sizeof(ipc_magic)); |
116 | memcpy(&data32[0], len, sizeof(*len)); | 119 | memcpy(&data32[0], len, sizeof(*len)); |
@@ -120,6 +123,8 @@ char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint3 | |||
120 | sway_abort("Unable to send IPC header"); | 123 | sway_abort("Unable to send IPC header"); |
121 | } | 124 | } |
122 | 125 | ||
126 | free(data); | ||
127 | |||
123 | if (write(socketfd, payload, *len) == -1) { | 128 | if (write(socketfd, payload, *len) == -1) { |
124 | sway_abort("Unable to send IPC payload"); | 129 | sway_abort("Unable to send IPC payload"); |
125 | } | 130 | } |