aboutsummaryrefslogtreecommitdiff
path: root/sway/readline.c
diff options
context:
space:
mode:
authorAlexander 'z33ky' Hirsch <1zeeky@gmail.com>2015-08-20 02:24:47 +0200
committerAlexander 'z33ky' Hirsch <1zeeky@gmail.com>2015-08-20 02:30:22 +0200
commitf85d0740a83c32f9ef4d7f73b3dd25cff3a6239a (patch)
tree9cbd38bb3ddad41ed436180acf6b8d6f7169bdde /sway/readline.c
parent22675b01118766c980d9c9c66453fb5d5318cdef (diff)
Fix potential memory leak
Diffstat (limited to 'sway/readline.c')
-rw-r--r--sway/readline.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/sway/readline.c b/sway/readline.c
index dfdc3fe8..e75b183f 100644
--- a/sway/readline.c
+++ b/sway/readline.c
@@ -17,18 +17,22 @@ char *read_line(FILE *file) {
continue;
}
if (length == size) {
- string = realloc(string, size *= 2);
- if (!string) {
+ char *new_string = realloc(string, size *= 2);
+ if (!new_string) {
+ free(string);
return NULL;
}
+ string = new_string;
}
string[length++] = c;
}
if (length + 1 == size) {
- string = realloc(string, length + 1);
- if (!string) {
+ char *new_string = realloc(string, length + 1);
+ if (!new_string) {
+ free(string);
return NULL;
}
+ string = new_string;
}
string[length] = '\0';
return string;