summaryrefslogtreecommitdiffstats
path: root/common/sysutils.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2022-11-30 07:56:03 +0100
committerNIIBE Yutaka <gniibe@fsij.org>2022-11-30 07:56:03 +0100
commit8e8971403f7510f4d7c746fc0ffcdef73c0baf8b (patch)
tree3ebc8b33dbfce109e538170aabce5b58903a6c14 /common/sysutils.c
parentdoc: Deprecate scd-event option of scdaemon. (diff)
downloadgnupg2-8e8971403f7510f4d7c746fc0ffcdef73c0baf8b.tar.xz
gnupg2-8e8971403f7510f4d7c746fc0ffcdef73c0baf8b.zip
w32: Fix gnupg_unsetenv.
* common/sysutils.c (gnupg_unsetenv): Don't use nonstandard extension of "NAME", but "NAME=". -- Microsoft implementation of putenv works to remove an environment variable by "NAME=". POSIX doesn't say that putenv with "NAME=" has same effect. GNU implementation doesn't support this way for removal of environment variable. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to '')
-rw-r--r--common/sysutils.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/common/sysutils.c b/common/sysutils.c
index ee9a25715..01510ddb0 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -1192,19 +1192,28 @@ gnupg_unsetenv (const char *name)
#else /*!HAVE_UNSETENV*/
{
char *buf;
+ int r;
if (!name)
{
gpg_err_set_errno (EINVAL);
return -1;
}
- buf = xtrystrdup (name);
+ buf = strconcat (name, "=", NULL);
if (!buf)
return -1;
+
+ r = putenv (buf);
+# ifdef HAVE_W32_SYSTEM
+ /* For Microsoft implementation, we can free the memory in this
+ use case. */
+ xfree (buf);
+# else
# if __GNUC__
# warning no unsetenv - trying putenv but leaking memory.
# endif
- return putenv (buf);
+# endif
+ return r;
}
#endif /*!HAVE_UNSETENV*/
}