From owner-svn-src-head@freebsd.org Sun Apr 16 21:42:45 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6971BD41F39; Sun, 16 Apr 2017 21:42:45 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2092814DE; Sun, 16 Apr 2017 21:42:45 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3GLginL035614; Sun, 16 Apr 2017 21:42:44 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3GLgin1035612; Sun, 16 Apr 2017 21:42:44 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201704162142.v3GLgin1035612@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sun, 16 Apr 2017 21:42:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r317037 - in head/bin/sh: . tests/parser X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Apr 2017 21:42:45 -0000 Author: jilles Date: Sun Apr 16 21:42:43 2017 New Revision: 317037 URL: https://svnweb.freebsd.org/changeset/base/317037 Log: 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. Added: head/bin/sh/tests/parser/alias17.0 (contents, props changed) Modified: head/bin/sh/alias.c Modified: head/bin/sh/alias.c ============================================================================== --- head/bin/sh/alias.c Sun Apr 16 19:23:10 2017 (r317036) +++ head/bin/sh/alias.c Sun Apr 16 21:42:43 2017 (r317037) @@ -85,6 +85,14 @@ setalias(const char *name, const char *v 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; Added: head/bin/sh/tests/parser/alias17.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/parser/alias17.0 Sun Apr 16 21:42:43 2017 (r317037) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +v=1 +alias a='unalias -a +v=2' +eval a +[ "$v" = 2 ]