diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 38153ed3..fb79c172 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -3815,7 +3815,8 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc modstk((int)declared*sizeof(cell)); /* remove all local variables */ declared=0; } /* if */ - if ((lastst!=tRETURN) && (lastst!=tGOTO) && (sym->flags & flagNAKED)==0){ + if ((lastst!=tRETURN) && (lastst!=tGOTO) && (sym->flags & flagNAKED)==0) { + destructsymbols(&loctab,0); ldconst(0,sPRI); ffret(strcmp(sym->name,uENTRYFUNC)!=0); if ((sym->usage & uRETVALUE)!=0) { @@ -4909,7 +4910,7 @@ static cell calc_array_datasize(symbol *sym, cell *offset) if (offset!=NULL) *offset=length*(*offset+sizeof(cell)); if (sublength>0) - length*=length*sublength; + length*=sublength; else length=0; } else { @@ -4925,7 +4926,7 @@ static void destructsymbols(symbol *root,int level) int savepri=FALSE; symbol *sym=root->next; while (sym!=NULL && sym->compound>=level) { - if (sym->ident==iVARIABLE || sym->ident==iARRAY) { + if ((sym->ident==iVARIABLE || sym->ident==iARRAY) && !(sym->vclass==sSTATIC && sym->fnumber==-1)) { char symbolname[16]; symbol *opsym; cell elements; @@ -4939,6 +4940,15 @@ static void destructsymbols(symbol *root,int level) } /* if */ /* if the variable is an array, get the number of elements */ if (sym->ident==iARRAY) { + /* according to the PAWN Implementer Guide, the destructor + * should be triggered for the data of the array only; hence + * if the array is a part of a larger array, it must be ignored + * as it's parent would(or has already) trigger(ed) the destructor + */ + if (sym->parent!=NULL) { + sym=sym->next; + continue; + } /* if */ elements=calc_array_datasize(sym,&offset); /* "elements" can be zero when the variable is declared like * new mytag: myvar[2][] = { {1, 2}, {3, 4} }