summaryrefslogtreecommitdiffstats
path: root/generic/tclEnv.c
diff options
context:
space:
mode:
authorhobbs <hobbs@noemail.net>1999-10-13 00:32:16 (GMT)
committerhobbs <hobbs@noemail.net>1999-10-13 00:32:16 (GMT)
commitb3ebb9f31b3690ced22dad3e24dcb2837a36cc03 (patch)
tree1571ad12165c15ae0be7cc1c8a8985a2be7393fa /generic/tclEnv.c
parent8a110ae5a710da9f79625abeaf8136f7179a94ae (diff)
downloadtcl-b3ebb9f31b3690ced22dad3e24dcb2837a36cc03.zip
tcl-b3ebb9f31b3690ced22dad3e24dcb2837a36cc03.tar.gz
tcl-b3ebb9f31b3690ced22dad3e24dcb2837a36cc03.tar.bz2
* generic/tclEnv.c: fixed mem leak with putenv and DStrings
FossilOrigin-Name: 7232e516554842ccc26c572e157a5c1f56117e9c
Diffstat (limited to 'generic/tclEnv.c')
-rw-r--r--generic/tclEnv.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/generic/tclEnv.c b/generic/tclEnv.c
index 4e5854e..f601da5 100644
--- a/generic/tclEnv.c
+++ b/generic/tclEnv.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclEnv.c,v 1.4 1999/04/16 00:46:46 stanton Exp $
+ * RCS: @(#) $Id: tclEnv.c,v 1.5 1999/10/13 00:32:17 hobbs Exp $
*/
#include "tclInt.h"
@@ -225,23 +225,23 @@ TclSetEnv(name, value)
p[nameLength] = '=';
strcpy(p+nameLength+1, value);
p2 = Tcl_UtfToExternalDString(NULL, p, -1, &envString);
- ckfree(p);
+
+ /*
+ * Copy the native string to heap memory.
+ */
+ p = (char *) ckrealloc(p, (unsigned) (strlen(p2) + 1));
+ strcpy(p, p2);
+ Tcl_DStringFree(&envString);
#ifdef USE_PUTENV
/*
* Update the system environment.
*/
- putenv(p2);
+ putenv(p);
index = TclpFindVariable(name, &length);
#else
- /*
- * Copy the native string to heap memory.
- */
-
- p = (char *) ckalloc((unsigned) (strlen(p2) + 1));
- strcpy(p, p2);
environ[index] = p;
#endif
@@ -251,9 +251,7 @@ TclSetEnv(name, value)
* update the string in the cache.
*/
- if (environ[index] != p) {
- Tcl_DStringFree(&envString);
- } else {
+ if (environ[index] == p) {
ReplaceString(oldValue, p);
}
@@ -381,8 +379,10 @@ TclUnsetEnv(name)
string[length+1] = '\0';
Tcl_UtfToExternalDString(NULL, string, -1, &envString);
- ckfree(string);
- string = Tcl_DStringValue(&envString);
+ string = ckrealloc(string, (unsigned) (Tcl_DStringLength(&envString)+1));
+ strcpy(string, Tcl_DStringValue(&envString));
+ Tcl_DStringFree(&envString);
+
putenv(string);
/*
@@ -391,9 +391,7 @@ TclUnsetEnv(name)
* update the string in the cache.
*/
- if (environ[index] != string) {
- Tcl_DStringFree(&envString);
- } else {
+ if (environ[index] == string) {
ReplaceString(oldValue, string);
}
#else
@@ -663,7 +661,3 @@ TclFinalizeEnvironment()
#endif
}
}
-
-
-
-