diff -up ksh-20100621/src/cmd/ksh93/sh/array.c.mleakfix ksh-20100621/src/cmd/ksh93/sh/array.c --- ksh-20100621/src/cmd/ksh93/sh/array.c.mleakfix 2010-05-24 20:27:05.000000000 +0200 +++ ksh-20100621/src/cmd/ksh93/sh/array.c 2013-07-02 17:37:42.991534675 +0200 @@ -1218,7 +1218,11 @@ void *nv_associative(register Namval_t * ap->header.scope = 0; } else + { + if((ap->header.nelem&ARRAY_MASK)==0 && (ap->cur=nv_search("0",ap->header.table,0))) + nv_associative(np,(char*)0,NV_ADELETE); dtclose(ap->header.table); + } return((void*)ap); case NV_ANEXT: if(!ap->pos) diff -up ksh-20100621/src/cmd/ksh93/sh/init.c.mleakfix ksh-20100621/src/cmd/ksh93/sh/init.c --- ksh-20100621/src/cmd/ksh93/sh/init.c.mleakfix 2013-07-02 17:37:42.963534441 +0200 +++ ksh-20100621/src/cmd/ksh93/sh/init.c 2013-07-02 17:37:42.992534683 +0200 @@ -460,18 +460,24 @@ static void put_cdpath(register Namval_t static void put_ifs(register Namval_t* np,const char *val,int flags,Namfun_t *fp) { register struct ifs *ip = (struct ifs*)fp; - Shell_t *shp; ip->ifsnp = 0; if(!val) { fp = nv_stack(np, NIL(Namfun_t*)); if(fp && !fp->nofree) + { free((void*)fp); + fp = 0; + } } if(val != np->nvalue.cp) nv_putv(np, val, flags, fp); - if(!val && !(flags&NV_CLONE) && (fp=np->nvfun) && !fp->disc && (shp=(Shell_t*)(fp->last))) - nv_stack(np,&((Init_t*)shp->init_context)->IFS_init.hdr); + if(!val) + { + if (fp) + fp->next = np->nvfun; + np->nvfun = fp; + } } /* diff -up ksh-20100621/src/cmd/ksh93/sh/name.c.mleakfix ksh-20100621/src/cmd/ksh93/sh/name.c --- ksh-20100621/src/cmd/ksh93/sh/name.c.mleakfix 2013-07-02 17:37:42.967534474 +0200 +++ ksh-20100621/src/cmd/ksh93/sh/name.c 2013-07-02 17:37:42.997534725 +0200 @@ -2177,6 +2177,8 @@ static void table_unset(Shell_t *shp, re nv_delete(nq,root,0); } } + if(nv_arrayptr(np)) + nv_putsub(np,NIL(char*),ARRAY_SCAN); _nv_unset(np,flags); nv_delete(np,root,0); } diff -up ksh-20100621/src/cmd/ksh93/sh/subshell.c.mleakfix ksh-20100621/src/cmd/ksh93/sh/subshell.c --- ksh-20100621/src/cmd/ksh93/sh/subshell.c.mleakfix 2013-07-02 17:37:42.978534566 +0200 +++ ksh-20100621/src/cmd/ksh93/sh/subshell.c 2013-07-02 17:47:50.574610743 +0200 @@ -313,6 +313,7 @@ static void nv_restore(struct subshell * flags |= NV_MINIMAL; if(nv_isarray(mp)) nv_putsub(mp,NIL(char*),ARRAY_SCAN); + nofree = mp->nvfun?mp->nvfun->nofree:0; _nv_unset(mp,NV_RDONLY|NV_CLONE); if(nv_isarray(np)) { @@ -322,9 +323,8 @@ static void nv_restore(struct subshell * nv_setsize(mp,nv_size(np)); if(!(flags&NV_MINIMAL)) mp->nvenv = np->nvenv; - nofree = mp->nvfun?mp->nvfun->nofree:0; - if((mp->nvfun = np->nvfun) && nofree) - mp->nvfun->nofree = nofree; + if(!nofree) + mp->nvfun = np->nvfun; if(nv_isattr(np,NV_IDENT)) { nv_offattr(np,NV_IDENT); @@ -332,13 +332,11 @@ static void nv_restore(struct subshell * } mp->nvflag = np->nvflag|(flags&NV_MINIMAL); if(nv_cover(mp)) - { nv_putval(mp, nv_getval(np),np->nvflag|NV_NOFREE); - if(!nv_isattr(np,NV_NOFREE)) - nv_offattr(mp,NV_NOFREE); - } else mp->nvalue.cp = np->nvalue.cp; + if(nofree && np->nvfun && !np->nvfun->nofree) + free((char*)np->nvfun); np->nvfun = 0; if(nv_isattr(mp,NV_EXPORT)) {