diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/ipc-client.c | 13 | ||||
-rw-r--r-- | common/list.c | 3 | ||||
-rw-r--r-- | common/log.c | 11 | ||||
-rw-r--r-- | common/readline.c | 3 |
4 files changed, 27 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) { } struct ipc_response *response = malloc(sizeof(struct ipc_response)); + if (!response) { + goto error_1; + } + total = 0; response->size = data32[0]; response->type = data32[1]; char *payload = malloc(response->size + 1); + if (!payload) { + goto error_2; + } + while (total < response->size) { ssize_t received = recv(socketfd, payload + total, response->size - total, 0); if (received < 0) { @@ -67,6 +75,11 @@ struct ipc_response *ipc_recv_response(int socketfd) { response->payload = payload; return response; +error_2: + free(response); +error_1: + sway_log(L_ERROR, "Unable to allocate memory for IPC response"); + return NULL; } void free_ipc_response(struct ipc_response *response) { diff --git a/common/list.c b/common/list.c index d57234e3..dd864a9b 100644 --- a/common/list.c +++ b/common/list.c @@ -5,6 +5,9 @@ list_t *create_list(void) { list_t *list = malloc(sizeof(list_t)); + if (!list) { + return NULL; + } list->capacity = 10; list->length = 0; list->items = malloc(sizeof(void*) * list->capacity); 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 } if (filename && line) { - char *file = strdup(filename); - fprintf(stderr, "[%s:%d] ", basename(file), line); - free(file); + const char *file = filename + strlen(filename); + while (file != filename && *file != '/') { + --file; + } + if (*file == '/') { + ++file; + } + fprintf(stderr, "[%s:%d] ", file, line); } va_list args; diff --git a/common/readline.c b/common/readline.c index 5106172c..cc40a2cc 100644 --- a/common/readline.c +++ b/common/readline.c @@ -1,4 +1,5 @@ #include "readline.h" +#include "log.h" #include <stdlib.h> #include <stdio.h> @@ -7,6 +8,7 @@ char *read_line(FILE *file) { char *string = malloc(size); char lastChar = '\0'; if (!string) { + sway_log(L_ERROR, "Unable to allocate memory for read_line"); return NULL; } while (1) { @@ -27,6 +29,7 @@ char *read_line(FILE *file) { char *new_string = realloc(string, size *= 2); if (!new_string) { free(string); + sway_log(L_ERROR, "Unable to allocate memory for read_line"); return NULL; } string = new_string; |