mirror of
https://github.com/NickHu/sway
synced 2024-11-16 19:49:56 +01:00
Fix potential memory leak
This commit is contained in:
parent
22675b0111
commit
f85d0740a8
1 changed files with 8 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue