diff options
author | jilles <jilles@FreeBSD.org> | 2016-01-22 20:10:08 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2016-01-22 20:10:08 +0000 |
commit | e81a328bbdaf3074c8509065e2a0b0e8b8b6116f (patch) | |
tree | 43ee86b07eb10ad8ab7029e64ebf416c8fc9e6b9 | |
parent | e270f2d00ed1836c651e7c382050e15d534383a1 (diff) | |
download | FreeBSD-src-e81a328bbdaf3074c8509065e2a0b0e8b8b6116f.zip FreeBSD-src-e81a328bbdaf3074c8509065e2a0b0e8b8b6116f.tar.gz |
sh: Clean a readonly local, even if the variable does not exist outside.
If a local variable has been made read-only, this should not prevent its
removal when the function returns.
-rw-r--r-- | bin/sh/tests/builtins/Makefile | 1 | ||||
-rw-r--r-- | bin/sh/tests/builtins/local7.0 | 10 | ||||
-rw-r--r-- | bin/sh/var.c | 1 |
3 files changed, 12 insertions, 0 deletions
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile index 4d94d94..4811bb3 100644 --- a/bin/sh/tests/builtins/Makefile +++ b/bin/sh/tests/builtins/Makefile @@ -113,6 +113,7 @@ FILES+= local3.0 FILES+= local4.0 FILES+= local5.0 FILES+= local6.0 +FILES+= local7.0 .if ${MK_NLS} != "no" FILES+= locale1.0 .endif diff --git a/bin/sh/tests/builtins/local7.0 b/bin/sh/tests/builtins/local7.0 new file mode 100644 index 0000000..f7e6fc0 --- /dev/null +++ b/bin/sh/tests/builtins/local7.0 @@ -0,0 +1,10 @@ +# $FreeBSD$ + +f() { + local x + readonly x=2 +} +unset x +f +x=4 +[ "$x" = 4 ] diff --git a/bin/sh/var.c b/bin/sh/var.c index 3af7dbe..03d529b 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -802,6 +802,7 @@ poplocalvars(void) ckfree(lvp->text); optschanged(); } else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) { + vp->flags &= ~VREADONLY; (void)unsetvar(vp->text); } else { islocalevar = (vp->flags | lvp->flags) & VEXPORT && |