From: NeilBrown Date: Tue, 12 Oct 2021 10:28:47 +0000 (+1100) Subject: oceani: fix a couple of issues X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=b5a63d46c787e442d44b5fd1d70d007498bd5058 oceani: fix a couple of issues 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 --- diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 6ea1204..90bfc19 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -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 diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index bc8880e..2804224 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -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;