Blame SOURCES/ksh-20120801-memlik3.patch

f38fd1
diff -up ksh-20120801/src/cmd/ksh93/include/name.h.memlik3 ksh-20120801/src/cmd/ksh93/include/name.h
f38fd1
--- ksh-20120801/src/cmd/ksh93/include/name.h.memlik3	2012-05-10 18:33:41.000000000 +0200
f38fd1
+++ ksh-20120801/src/cmd/ksh93/include/name.h	2014-01-22 14:14:32.774483776 +0100
f38fd1
@@ -215,7 +215,7 @@ extern Namval_t		*nv_mount(Namval_t*, co
f38fd1
 extern Namval_t		*nv_arraychild(Namval_t*, Namval_t*, int);
f38fd1
 extern int		nv_compare(Dt_t*, Void_t*, Void_t*, Dtdisc_t*);
f38fd1
 extern void		nv_outnode(Namval_t*,Sfio_t*, int, int);
f38fd1
-extern int		nv_subsaved(Namval_t*);
f38fd1
+extern int		nv_subsaved(Namval_t*,int);
f38fd1
 extern void		nv_typename(Namval_t*, Sfio_t*);
f38fd1
 extern void		nv_newtype(Namval_t*);
f38fd1
 extern int		nv_istable(Namval_t*);
f38fd1
diff -up ksh-20120801/src/cmd/ksh93/sh/name.c.memlik3 ksh-20120801/src/cmd/ksh93/sh/name.c
f38fd1
--- ksh-20120801/src/cmd/ksh93/sh/name.c.memlik3	2014-01-22 14:14:32.751483987 +0100
f38fd1
+++ ksh-20120801/src/cmd/ksh93/sh/name.c	2014-01-22 14:14:32.775483767 +0100
f38fd1
@@ -1297,7 +1297,7 @@ void nv_delete(Namval_t* np, Dt_t *root,
f38fd1
 	{
f38fd1
 		if(dtdelete(root,np))
f38fd1
 		{
f38fd1
-			if(!(flags&NV_NOFREE) && ((flags&NV_FUNCTION) || !nv_subsaved(np)))
f38fd1
+			if(!(flags&NV_NOFREE) && ((flags&NV_FUNCTION) || !nv_subsaved(np,flags&NV_TABLE)))
f38fd1
 				free((void*)np);
f38fd1
 		}
f38fd1
 #if 0
f38fd1
@@ -2461,14 +2461,14 @@ static void table_unset(Shell_t *shp, re
f38fd1
 			{
f38fd1
 				_nv_unset(nq,flags);
f38fd1
 				npnext = (Namval_t*)dtnext(root,nq);
f38fd1
-				nv_delete(nq,root,0);
f38fd1
+				nv_delete(nq,root,NV_TABLE);
f38fd1
 			}
f38fd1
 		}
f38fd1
 		npnext = (Namval_t*)dtnext(root,np);
f38fd1
                if(nv_arrayptr(np))
f38fd1
                        nv_putsub(np,NIL(char*),ARRAY_SCAN);
f38fd1
 		_nv_unset(np,flags);
f38fd1
-		nv_delete(np,root,0);
f38fd1
+		nv_delete(np,root,NV_TABLE);
f38fd1
 	}
f38fd1
 }
f38fd1
 
f38fd1
diff -up ksh-20120801/src/cmd/ksh93/sh/subshell.c.memlik3 ksh-20120801/src/cmd/ksh93/sh/subshell.c
f38fd1
--- ksh-20120801/src/cmd/ksh93/sh/subshell.c.memlik3	2014-01-22 14:14:32.768483831 +0100
f38fd1
+++ ksh-20120801/src/cmd/ksh93/sh/subshell.c	2014-01-22 14:20:50.810236676 +0100
f38fd1
@@ -218,16 +218,28 @@ void sh_subfork(void)
f38fd1
 	}
f38fd1
 }
f38fd1
 
f38fd1
-int nv_subsaved(register Namval_t *np)
f38fd1
+int nv_subsaved(register Namval_t *np,int table)
f38fd1
 {
f38fd1
 	register struct subshell	*sp;
f38fd1
-	register struct Link		*lp;
f38fd1
+	register struct Link		*lp, *lpprev;
f38fd1
 	for(sp = (struct subshell*)subshell_data; sp; sp=sp->prev)
f38fd1
 	{
f38fd1
-		for(lp=sp->svar; lp; lp = lp->next)
f38fd1
+		lpprev = 0;
f38fd1
+		for(lp=sp->svar; lp; lpprev=lp, lp=lp->next)
f38fd1
 		{
f38fd1
 			if(lp->node==np)
f38fd1
+			{
f38fd1
+				if(table&NV_TABLE)
f38fd1
+				{
f38fd1
+					if(lpprev)
f38fd1
+						lpprev->next = lp->next;
f38fd1
+					else
f38fd1
+						sp->svar = lp->next;
f38fd1
+					free((void*)np);
f38fd1
+					free((void*)lp);
f38fd1
+				}
f38fd1
 				return(1);
f38fd1
+			}
f38fd1
 		}
f38fd1
 	}
f38fd1
 	return(0);