]> ocean-lang.org Git - ocean/commitdiff
oceani: fix a couple of issues
authorNeilBrown <neil@brown.name>
Tue, 12 Oct 2021 10:28:47 +0000 (21:28 +1100)
committerNeilBrown <neil@brown.name>
Tue, 12 Oct 2021 10:28:47 +0000 (21:28 +1100)
1/ when a variable declared in a loop was re-initialized, we didn't free
   the old value before allocating a new one.
2/ When assigning to an out-of-bounds array index, created an rval,
   but never freed it.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index 6ea120447b33dd3134339efcb819776d6eff89c9..90bfc19da11d84241256fdba41c6b06bd5376db9 100644 (file)
@@ -532,11 +532,15 @@ ad-hoc things array related.
                bools[1] = strings[2] <= "there"
 
                for i:=0; then i=i+1; while i<5:
-                       print '', bools[i],
+                       j ::= i
+                       ra:[5]number
+                       ra[i-1] = i*i
+                       ra[6] = 42 // mustn't crash
+                       print '', bools[i], ra[j-1],
                print
 
 ###### output: arrays
-        False True False False False
+        False 0 True 1 False 4 False 9 False 16
 
 ## Structures
 
index bc8880e72ccaf11343c1782ff6d7670db537f114..2804224da5759f95e08ef7cb4f0ce17618607551 100644 (file)
@@ -1437,8 +1437,10 @@ in `rval`.
        {
                struct lrval ret = _interp_exec(e);
 
-               if (typeret)
+               if (ret.lval)
                        *typeret = ret.type;
+               else
+                       free_value(ret.type, &ret.rval);
                return ret.lval;
        }
 
@@ -3362,6 +3364,7 @@ it is declared, and error will be raised as the name is created as
                        rtype = Tnone;
                } else {
                        free_value(v->type, v->val);
+                       free(v->val);
                        v->val = val_alloc(v->type, NULL);
                }
                break;