diff options
-rw-r--r-- | common/ipc-client.c | 13 | ||||
-rw-r--r-- | common/log.c | 11 | ||||
-rw-r--r-- | swaybar/ipc.c | 3 |
3 files changed, 24 insertions, 3 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) { |
diff --git a/common/log.c b/common/log.c index 4f0baa3f..825b176b 100644 --- a/common/log.c +++ b/common/log.c | |||
@@ -88,9 +88,14 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const | |||
88 | } | 88 | } |
89 | 89 | ||
90 | if (filename && line) { | 90 | if (filename && line) { |
91 | char *file = strdup(filename); | 91 | const char *file = filename + strlen(filename); |
92 | fprintf(stderr, "[%s:%d] ", basename(file), line); | 92 | while (file != filename && *file != '/') { |
93 | free(file); | 93 | --file; |
94 | } | ||
95 | if (*file == '/') { | ||
96 | ++file; | ||
97 | } | ||
98 | fprintf(stderr, "[%s:%d] ", file, line); | ||
94 | } | 99 | } |
95 | 100 | ||
96 | va_list args; | 101 | va_list args; |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 8d2f4e9a..f2da7392 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -331,6 +331,9 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) { | |||
331 | 331 | ||
332 | bool handle_ipc_event(struct bar *bar) { | 332 | bool handle_ipc_event(struct bar *bar) { |
333 | struct ipc_response *resp = ipc_recv_response(bar->ipc_event_socketfd); | 333 | struct ipc_response *resp = ipc_recv_response(bar->ipc_event_socketfd); |
334 | if (!resp) { | ||
335 | return false; | ||
336 | } | ||
334 | switch (resp->type) { | 337 | switch (resp->type) { |
335 | case IPC_EVENT_WORKSPACE: | 338 | case IPC_EVENT_WORKSPACE: |
336 | ipc_update_workspaces(bar); | 339 | ipc_update_workspaces(bar); |