From 8d1532abb6f7441e00ffbc7ed4d0231e5023e19a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 9 Aug 2020 08:36:33 +0200 Subject: Cleanup file data if file read fails --- src/parser.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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); } -- cgit v1.2.3