about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2015-01-30 20:03:02 +0000
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2015-01-30 20:03:02 +0000
commitce211bb8d11a030dbb9ad99f9590a378efdd4580 (patch)
treeb43e507c66b7713289fe0206827e548628317b5c /Src
parent1c942291f8a41d80d7db4e7513adf06edfe50277 (diff)
downloadzsh-ce211bb8d11a030dbb9ad99f9590a378efdd4580.tar.gz
zsh-ce211bb8d11a030dbb9ad99f9590a378efdd4580.tar.xz
zsh-ce211bb8d11a030dbb9ad99f9590a378efdd4580.zip
34439: unset variable about to be tied
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/db_gdbm.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index a6027deaf..9896bb536 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -77,8 +77,6 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
 	return 1;
     }
 
-    pmname = ztrdup(*args);
-
     resource_name = OPT_ARG(ops, 'f');
 
     dbf = gdbm_open(resource_name, 0, GDBM_WRCREAT | GDBM_SYNC, 0666, 0);
@@ -87,6 +85,21 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
 	return 1;
     }
 
+    pmname = ztrdup(*args);
+
+    if ((tied_param = (Param)paramtab->getnode(paramtab, pmname)) &&
+	!(tied_param->node.flags & PM_UNSET)) {
+	/*
+	 * Unset any existing parameter.  Note there's no implicit
+	 * "local" here, but if the existing parameter is local
+	 * that will be reflected in the new one.
+	 */
+	if (unsetparam_pm(tied_param, 0, 1)) {
+	    zsfree(pmname);
+	    gdbm_close(dbf);
+	    return 1;
+	}
+    }
     if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys,
 					 PM_REMOVABLE))) {
         zwarnnam(nam, "cannot create the requested parameter %s", pmname);