From e337fbef5e42c992089fe1e51292f2f82380642d Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 10 May 2019 20:25:01 +1000 Subject: [PATCH] oceani: fix valgrind-reported errors. The test suite wasn't running valgrind in a useful way, and wasn't actually reporting errors. So fix it to report leaks and unfreed memory, and then fix the bugs that it finds. Signed-off-by: NeilBrown --- csrc/oceani-tests.mdc | 8 ++++++-- csrc/oceani.mdc | 30 +++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index bba5156..8649f6e 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -50,9 +50,13 @@ arguments separated from the name by commas. For each test, there is a section if ! cmp -s .tmp.want .tmp.have; then \ echo "FAILED"; diff -u .tmp.want .tmp.have ; exit 1; fi ;\ echo -n "passed ... "; \ - if ! valgrind ./oceani --section "test: $$t" oceani-tests.mdc $${1+"$$@"} \ - > /dev/null 2> .tmp.valg; then \ + if ! valgrind --error-exitcode=1 --log-file=.tmp.valg ./oceani --section "test: $$t" oceani-tests.mdc $${1+"$$@"} \ + > /dev/null 2>&1 ; then \ echo "valgrind FAILED"; cat .tmp.valg; exit 1; fi ; \ + if grep 'LEAK SUMMARY' .tmp.valg > /dev/null; then \ + echo "valgrind found LEAKS"; cat .tmp.valg ; exit 1 ; fi; \ + if grep 'in use at exit [1-9]' .tmp.valg > /dev/null; then \ + echo "valgrind found memory in use at exit"; cat .tmp.valg ; exit 1 ; fi; \ echo -n "valgrind passed ... "; \ echo '``````' > .tmp.code1; echo '``````' > .tmp.code2 ;\ ./oceani --noexec --print --section "test: $$t" oceani-tests.mdc >> .tmp.code1; \ diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 07caefa..02968bb 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -3430,26 +3430,31 @@ make a copy of an array with controllable depth. $0->array.member = $<4; $0->array.vsize = NULL; { + struct parse_context *c = config2context(config); char tail[3]; mpq_t num; if (number_parse(num, tail, $2.txt) == 0) - tok_err(config2context(config), "error: unrecognised number", &$2); + tok_err(c, "error: unrecognised number", &$2); else if (tail[0]) - tok_err(config2context(config), "error: unsupported number suffix", &$2); + tok_err(c, "error: unsupported number suffix", &$2); else { $0->array.size = mpz_get_ui(mpq_numref(num)); if (mpz_cmp_ui(mpq_denref(num), 1) != 0) { - tok_err(config2context(config), "error: array size must be an integer", + tok_err(c, "error: array size must be an integer", &$2); } else if (mpz_cmp_ui(mpq_numref(num), 1UL << 30) >= 0) - tok_err(config2context(config), "error: array size is too large", + tok_err(c, "error: array size is too large", &$2); + mpq_clear(num); } + $0->next= c->anon_typelist; + c->anon_typelist = $0; } }$ | [ IDENTIFIER ] Type ${ { - struct variable *v = var_ref(config2context(config), $2.txt); + struct parse_context *c = config2context(config); + struct variable *v = var_ref(c, $2.txt); if (!v) tok_err(config2context(config), "error: name undeclared", &$2); @@ -3461,8 +3466,23 @@ make a copy of an array with controllable depth. $0->array.member = $<4; $0->array.size = 0; $0->array.vsize = v; + $0->next= c->anon_typelist; + c->anon_typelist = $0; } }$ +###### parse context + + struct type *anon_typelist; + +###### free context types + + while (context.anon_typelist) { + struct type *t = context.anon_typelist; + + context.anon_typelist = t->next; + free(t); + } + ###### Binode types Index, -- 2.43.0