]> ocean-lang.org Git - ocean/commitdiff
oceani: fix valgrind-reported errors.
authorNeilBrown <neil@brown.name>
Fri, 10 May 2019 10:25:01 +0000 (20:25 +1000)
committerNeilBrown <neil@brown.name>
Fri, 10 May 2019 10:25:01 +0000 (20:25 +1000)
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 <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index bba5156a16b05f1c084afbc7404b975ffacc73ca..8649f6e2e77290fe3dbde90f7d83835d67eee4c0 100644 (file)
@@ -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; \
index 07caefafca523bf1014752bf1cc228f0f7689a72..02968bb473926333f3341ed78663d24d2b9144dd 100644 (file)
@@ -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,