aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2016-12-15 17:08:56 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2016-12-15 19:01:40 -0500
commit4c6c65e70cbe1e6b4b409ba18b71b2a8fb251d83 (patch)
treea1c7455f1a81bea1d40427440c32461008b7a524 /common
parentHandle malloc failure in ipc_recv_response (diff)
downloadsway-4c6c65e70cbe1e6b4b409ba18b71b2a8fb251d83.tar.gz
sway-4c6c65e70cbe1e6b4b409ba18b71b2a8fb251d83.tar.zst
sway-4c6c65e70cbe1e6b4b409ba18b71b2a8fb251d83.zip
Handle malloc failures from read_line
Diffstat (limited to 'common')
-rw-r--r--common/readline.c3
1 files changed, 3 insertions, 0 deletions
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;