sh: Fix unalias -a while an alias is currently in use.
It is a rare situation to modify aliases while an alias is currently in use, but this is handled for plain unalias. Handle it for unalias -a as well.
This commit is contained in:
parent
6fd94039ef
commit
773e27aeee
@ -85,6 +85,14 @@ setalias(const char *name, const char *val)
|
||||
INTON;
|
||||
}
|
||||
|
||||
static void
|
||||
freealias(struct alias *ap)
|
||||
{
|
||||
ckfree(ap->name);
|
||||
ckfree(ap->val);
|
||||
ckfree(ap);
|
||||
}
|
||||
|
||||
static int
|
||||
unalias(const char *name)
|
||||
{
|
||||
@ -106,9 +114,7 @@ unalias(const char *name)
|
||||
else {
|
||||
INTOFF;
|
||||
*app = ap->next;
|
||||
ckfree(ap->name);
|
||||
ckfree(ap->val);
|
||||
ckfree(ap);
|
||||
freealias(ap);
|
||||
INTON;
|
||||
}
|
||||
aliases--;
|
||||
@ -122,19 +128,21 @@ unalias(const char *name)
|
||||
static void
|
||||
rmaliases(void)
|
||||
{
|
||||
struct alias *ap, *tmp;
|
||||
struct alias *ap, **app;
|
||||
int i;
|
||||
|
||||
INTOFF;
|
||||
for (i = 0; i < ATABSIZE; i++) {
|
||||
ap = atab[i];
|
||||
atab[i] = NULL;
|
||||
while (ap) {
|
||||
ckfree(ap->name);
|
||||
ckfree(ap->val);
|
||||
tmp = ap;
|
||||
ap = ap->next;
|
||||
ckfree(tmp);
|
||||
app = &atab[i];
|
||||
while (*app) {
|
||||
ap = *app;
|
||||
if (ap->flag & ALIASINUSE) {
|
||||
*ap->name = '\0';
|
||||
app = &(*app)->next;
|
||||
} else {
|
||||
*app = ap->next;
|
||||
freealias(ap);
|
||||
}
|
||||
}
|
||||
}
|
||||
aliases = 0;
|
||||
|
7
bin/sh/tests/parser/alias17.0
Normal file
7
bin/sh/tests/parser/alias17.0
Normal file
@ -0,0 +1,7 @@
|
||||
# $FreeBSD$
|
||||
|
||||
v=1
|
||||
alias a='unalias -a
|
||||
v=2'
|
||||
eval a
|
||||
[ "$v" = 2 ]
|
Loading…
Reference in New Issue
Block a user