diff options
author | scf <scf@FreeBSD.org> | 2007-07-04 00:00:41 +0000 |
---|---|---|
committer | scf <scf@FreeBSD.org> | 2007-07-04 00:00:41 +0000 |
commit | 196b6346ba4e13a3f7679e2de3317b6aa65983df (patch) | |
tree | 423c7d016f87f6541b9ef8231a14f8b267bc5d5e /usr.sbin | |
parent | af5bbfbc7b6a610f0c44a56a7b2d81b96be9b1b5 (diff) | |
download | FreeBSD-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 'usr.sbin')
-rw-r--r-- | usr.sbin/pstat/pstat.c | 6 | ||||
-rw-r--r-- | usr.sbin/sade/main.c | 2 | ||||
-rw-r--r-- | usr.sbin/sade/variable.c | 5 | ||||
-rw-r--r-- | usr.sbin/sysinstall/main.c | 2 | ||||
-rw-r--r-- | usr.sbin/sysinstall/variable.c | 5 |
5 files changed, 13 insertions, 7 deletions
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c index 95f782c..1516365 100644 --- a/usr.sbin/pstat/pstat.c +++ b/usr.sbin/pstat/pstat.c @@ -135,16 +135,16 @@ main(int argc, char *argv[]) fileflag = 1; break; case 'g': - putenv("BLOCKSIZE=1G"); + setenv("BLOCKSIZE", "1G", 1); break; case 'h': humanflag = 1; break; case 'k': - putenv("BLOCKSIZE=1K"); + setenv("BLOCKSIZE", "1K", 1); break; case 'm': - putenv("BLOCKSIZE=1M"); + setenv("BLOCKSIZE", "1M", 1); break; case 'M': memf = optarg; diff --git a/usr.sbin/sade/main.c b/usr.sbin/sade/main.c index 45ed1bb..5496e13 100644 --- a/usr.sbin/sade/main.c +++ b/usr.sbin/sade/main.c @@ -56,7 +56,7 @@ main(int argc, char **argv) /* XXX */ char *p = getenv("TERM"); if (p && strcmp(p, "cons25") == 0) - putenv("TERM=cons25w"); + setenv("TERM", "cons25w", 1); } #endif diff --git a/usr.sbin/sade/variable.c b/usr.sbin/sade/variable.c index bbbc2d2..7809deb 100644 --- a/usr.sbin/sade/variable.c +++ b/usr.sbin/sade/variable.c @@ -296,6 +296,7 @@ free_variables(void) void pvariable_set(char *var) { + char *p; char tmp[1024]; if (!var) @@ -307,7 +308,9 @@ pvariable_set(char *var) if (index(var, '=') == NULL) msgFatal("Invalid variable format: %s", var); strlcat(tmp, var, 1024); - putenv(tmp); + p = strchr(tmp, '='); + *p = '\0'; + setenv(tmp, p + 1, 1); } char * diff --git a/usr.sbin/sysinstall/main.c b/usr.sbin/sysinstall/main.c index 7af8d44..149a0dc 100644 --- a/usr.sbin/sysinstall/main.c +++ b/usr.sbin/sysinstall/main.c @@ -74,7 +74,7 @@ main(int argc, char **argv) /* XXX */ char *p = getenv("TERM"); if (p && strcmp(p, "cons25") == 0) - putenv("TERM=cons25w"); + setenv("TERM", "cons25w", 1); } #endif diff --git a/usr.sbin/sysinstall/variable.c b/usr.sbin/sysinstall/variable.c index e86104f..694b8be 100644 --- a/usr.sbin/sysinstall/variable.c +++ b/usr.sbin/sysinstall/variable.c @@ -301,6 +301,7 @@ free_variables(void) void pvariable_set(char *var) { + char *p; char tmp[1024]; if (!var) @@ -312,7 +313,9 @@ pvariable_set(char *var) if (index(var, '=') == NULL) msgFatal("Invalid variable format: %s", var); strlcat(tmp, var, 1024); - putenv(tmp); + p = strchr(tmp, '='); + *p = '\0'; + setenv(tmp, p + 1, 1); } char * |