summaryrefslogtreecommitdiffstats
path: root/bin/sh/var.c
diff options
context:
space:
mode:
authorscf <scf@FreeBSD.org>2007-07-04 00:00:41 +0000
committerscf <scf@FreeBSD.org>2007-07-04 00:00:41 +0000
commit196b6346ba4e13a3f7679e2de3317b6aa65983df (patch)
tree423c7d016f87f6541b9ef8231a14f8b267bc5d5e /bin/sh/var.c
parentaf5bbfbc7b6a610f0c44a56a7b2d81b96be9b1b5 (diff)
downloadFreeBSD-src-196b6346ba4e13a3f7679e2de3317b6aa65983df.zip
FreeBSD-src-196b6346ba4e13a3f7679e2de3317b6aa65983df.tar.gz
Significantly reduce the memory leak as noted in BUGS section for
setenv(3) by tracking the size of the memory allocated instead of using strlen() on the current value. Convert all calls to POSIX from historic BSD API: - unsetenv returns an int. - putenv takes a char * instead of const char *. - putenv no longer makes a copy of the input string. - errno is set appropriately for POSIX. Exceptions involve bad environ variable and internal initialization code. These both set errno to EFAULT. Several patches to base utilities to handle the POSIX changes from Andrey Chernov's previous commit. A few I re-wrote to use setenv() instead of putenv(). New regression module for tools/regression/environ to test these functions. It also can be used to test the performance. Bump __FreeBSD_version to 700050 due to API change. PR: kern/99826 Approved by: wes Approved by: re (kensmith)
Diffstat (limited to 'bin/sh/var.c')
-rw-r--r--bin/sh/var.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/bin/sh/var.c b/bin/sh/var.c
index 54a0a84..afb3c86 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -289,6 +289,7 @@ void
setvareq(char *s, int flags)
{
struct var *vp, **vpp;
+ char *p;
int len;
if (aflag)
@@ -319,7 +320,10 @@ setvareq(char *s, int flags)
if (vp == &vmpath || (vp == &vmail && ! mpathset()))
chkmail(1);
if ((vp->flags & VEXPORT) && localevar(s)) {
- putenv(s);
+ p = strchr(s, '=');
+ *p = '\0';
+ (void) setenv(s, p + 1, 1);
+ *p = '=';
(void) setlocale(LC_ALL, "");
}
INTON;
@@ -335,7 +339,10 @@ setvareq(char *s, int flags)
INTOFF;
*vpp = vp;
if ((vp->flags & VEXPORT) && localevar(s)) {
- putenv(s);
+ p = strchr(s, '=');
+ *p = '\0';
+ (void) setenv(s, p + 1, 1);
+ *p = '=';
(void) setlocale(LC_ALL, "");
}
INTON;
@@ -596,7 +603,10 @@ exportcmd(int argc, char **argv)
vp->flags |= flag;
if ((vp->flags & VEXPORT) && localevar(vp->text)) {
- putenv(vp->text);
+ p = strchr(vp->text, '=');
+ *p = '\0';
+ (void) setenv(vp->text, p + 1, 1);
+ *p = '=';
(void) setlocale(LC_ALL, "");
}
goto found;
OpenPOWER on IntegriCloud