aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-08-09 08:36:33 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-09 08:36:33 +0200
commit8d1532abb6f7441e00ffbc7ed4d0231e5023e19a (patch)
treefd93d17d322d9e7564cccb58381e5b5f3bf0ac26
parent9773f0df7f663ddf666db5a54961ad0228490e60 (diff)
Cleanup file data if file read fails
-rw-r--r--src/parser.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/parser.c b/src/parser.c
index e622b5f..c136a36 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1035,12 +1035,17 @@ int parser_parse_buffer(Parser *self, BufferView code_buffer, BufferView buffer_
}
int parser_parse_file(Parser *self, BufferView filepath) {
+ int result;
Buffer file_content;
return_if_error(buffer_init(&file_content, self->allocator));
assert(!self->started && "Parser can't be reused. Create a new parser.");
self->started = bool_true;
assert(filepath.size > 0 && filepath.data[filepath.size] == '\0');
- return_if_error(read_whole_file(filepath.data, &file_content));
+ result = read_whole_file(filepath.data, &file_content);
+ if(result != 0) {
+ buffer_deinit(&file_content);
+ return result;
+ }
return parser_parse_buffer(self, create_buffer_view(file_content.data, file_content.size), filepath);
}