changeset 95:4967652fcbf5

parse: Add note about reported memory leak
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 26 Aug 2019 17:00:25 +0200
parents d6afe40a6784
children f2b65c8f6a24
files src/parse.c src/parse_test.c
diffstat 2 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/parse.c	Mon Aug 26 17:00:08 2019 +0200
+++ b/src/parse.c	Mon Aug 26 17:00:25 2019 +0200
@@ -4,7 +4,7 @@
 int y_bison_parse(FILE* input, yvec_t* out, ystr_t* err);
 
 bool yparse_str(ystr_t* input, yexpr_t* result, ystr_t* error) {
-    char* contents = ystr_str(input);
+    char* contents = (char*)ystr_str(input);
     FILE* stream = fmemopen(contents, ystr_len(input), "r");
     bool ret = yparse(stream, result, error);
     fclose(stream);
--- a/src/parse_test.c	Mon Aug 26 17:00:08 2019 +0200
+++ b/src/parse_test.c	Mon Aug 26 17:00:25 2019 +0200
@@ -24,6 +24,10 @@
     fclose(input_f);
 }
 
+// NOTE: It is expected that valgrind reports leaked memory here, as the parser
+// code will strdup() some strings that are not reachable afterwards. It doesn't
+// matter usually, because the program execution will usually stop shortly after
+// a parsing failure.
 void test_parse_fail(void) {
     const char* invalid_input = "(hello 'world";
     FILE* input_f = fmemopen((char*)invalid_input, strlen(invalid_input),