diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-12-15 17:05:12 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-12-15 19:01:40 -0500 |
commit | 9ad1e6b40f9589a5ab8242dd3b2e514b70d97799 (patch) | |
tree | 2e80e1258f5e1af0465a7dfd9959397f7009e6df /common/ipc-client.c | |
parent | Merge pull request #991 from barfoo1/registry_fix (diff) | |
download | sway-9ad1e6b40f9589a5ab8242dd3b2e514b70d97799.tar.gz sway-9ad1e6b40f9589a5ab8242dd3b2e514b70d97799.tar.zst sway-9ad1e6b40f9589a5ab8242dd3b2e514b70d97799.zip |
Handle malloc failure in ipc_recv_response
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) { |