summaryrefslogtreecommitdiffstats
path: root/generic/tclEnv.c
diff options
context:
space:
mode:
authorhobbs <hobbs>1999-10-13 00:32:16 (GMT)
committerhobbs <hobbs>1999-10-13 00:32:16 (GMT)
commitc732fecaa0babcee5b1a681696d9366d226d6849 (patch)
tree1571ad12165c15ae0be7cc1c8a8985a2be7393fa /generic/tclEnv.c
parent95a22713b09018e80408b1a34c28326093361cb8 (diff)
downloadtcl-c732fecaa0babcee5b1a681696d9366d226d6849.zip
tcl-c732fecaa0babcee5b1a681696d9366d226d6849.tar.gz
tcl-c732fecaa0babcee5b1a681696d9366d226d6849.tar.bz2
* generic/tclEnv.c: fixed mem leak with putenv and DStrings
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
}
}
-
-
-
-