diff options
author | 2016-12-17 13:23:44 -0500 | |
---|---|---|
committer | 2016-12-17 13:23:44 -0500 | |
commit | f04ee0e68d885d7e1101cc88f9a9337202041f1f (patch) | |
tree | fa4dc296a5f1377867752d320ceef4e4b0178bbf /common/ipc-client.c | |
parent | Merge pull request #991 from barfoo1/registry_fix (diff) | |
parent | Fix build error (diff) | |
download | sway-f04ee0e68d885d7e1101cc88f9a9337202041f1f.tar.gz sway-f04ee0e68d885d7e1101cc88f9a9337202041f1f.tar.zst sway-f04ee0e68d885d7e1101cc88f9a9337202041f1f.zip |
Merge pull request #995 from SirCmpwn/memory-use
Handle allocation failures
Diffstat (limited to 'common/ipc-client.c')
-rw-r--r-- | common/ipc-client.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c index 106f9d86..d011bd26 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c | |||
@@ -52,10 +52,18 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
52 | } | 52 | } |
53 | 53 | ||
54 | struct ipc_response *response = malloc(sizeof(struct ipc_response)); | 54 | struct ipc_response *response = malloc(sizeof(struct ipc_response)); |
55 | if (!response) { | ||
56 | goto error_1; | ||
57 | } | ||
58 | |||
55 | total = 0; | 59 | total = 0; |
56 | response->size = data32[0]; | 60 | response->size = data32[0]; |
57 | response->type = data32[1]; | 61 | response->type = data32[1]; |
58 | char *payload = malloc(response->size + 1); | 62 | char *payload = malloc(response->size + 1); |
63 | if (!payload) { | ||
64 | goto error_2; | ||
65 | } | ||
66 | |||
59 | while (total < response->size) { | 67 | while (total < response->size) { |
60 | ssize_t received = recv(socketfd, payload + total, response->size - total, 0); | 68 | ssize_t received = recv(socketfd, payload + total, response->size - total, 0); |
61 | if (received < 0) { | 69 | if (received < 0) { |
@@ -67,6 +75,11 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
67 | response->payload = payload; | 75 | response->payload = payload; |
68 | 76 | ||
69 | return response; | 77 | return response; |
78 | error_2: | ||
79 | free(response); | ||
80 | error_1: | ||
81 | sway_log(L_ERROR, "Unable to allocate memory for IPC response"); | ||
82 | return NULL; | ||
70 | } | 83 | } |
71 | 84 | ||
72 | void free_ipc_response(struct ipc_response *response) { | 85 | void free_ipc_response(struct ipc_response *response) { |