summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/ipc-client.c13
-rw-r--r--common/list.c3
-rw-r--r--common/log.c11
-rw-r--r--common/readline.c3
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) {
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;
78error_2:
79 free(response);
80error_1:
81 sway_log(L_ERROR, "Unable to allocate memory for IPC response");
82 return NULL;
70} 83}
71 84
72void free_ipc_response(struct ipc_response *response) { 85void 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 @@
5 5
6list_t *create_list(void) { 6list_t *create_list(void) {
7 list_t *list = malloc(sizeof(list_t)); 7 list_t *list = malloc(sizeof(list_t));
8 if (!list) {
9 return NULL;
10 }
8 list->capacity = 10; 11 list->capacity = 10;
9 list->length = 0; 12 list->length = 0;
10 list->items = malloc(sizeof(void*) * list->capacity); 13 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
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/common/readline.c b/common/readline.c
index 5106172c..cc40a2cc 100644
--- a/common/readline.c
+++ b/common/readline.c
@@ -1,4 +1,5 @@
1#include "readline.h" 1#include "readline.h"
2#include "log.h"
2#include <stdlib.h> 3#include <stdlib.h>
3#include <stdio.h> 4#include <stdio.h>
4 5
@@ -7,6 +8,7 @@ char *read_line(FILE *file) {
7 char *string = malloc(size); 8 char *string = malloc(size);
8 char lastChar = '\0'; 9 char lastChar = '\0';
9 if (!string) { 10 if (!string) {
11 sway_log(L_ERROR, "Unable to allocate memory for read_line");
10 return NULL; 12 return NULL;
11 } 13 }
12 while (1) { 14 while (1) {
@@ -27,6 +29,7 @@ char *read_line(FILE *file) {
27 char *new_string = realloc(string, size *= 2); 29 char *new_string = realloc(string, size *= 2);
28 if (!new_string) { 30 if (!new_string) {
29 free(string); 31 free(string);
32 sway_log(L_ERROR, "Unable to allocate memory for read_line");
30 return NULL; 33 return NULL;
31 } 34 }
32 string = new_string; 35 string = new_string;