summaryrefslogtreecommitdiffstats
path: root/generic
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
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')
-rw-r--r--generic/tcl.h3
-rw-r--r--generic/tclEnv.c36
2 files changed, 17 insertions, 22 deletions
diff --git a/generic/tcl.h b/generic/tcl.h
index 34fb82f..f200531 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -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: tcl.h,v 1.58 1999/10/05 22:45:39 hobbs Exp $
+ * RCS: @(#) $Id: tcl.h,v 1.59 1999/10/13 00:32:16 hobbs Exp $
*/
#ifndef _TCL
@@ -48,6 +48,7 @@ extern "C" {
* win/README.binary (sections 0-4)
* win/README (not patchlevel) (sections 0 and 2)
* unix/README (not patchlevel) (part (h))
+ * tests/basic.test (not patchlevel) (version checks)
* tools/tcl.hpj.in (not patchlevel, for windows installer)
* tools/tcl.wse.in (for windows installer)
*/
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
}
}
-
-
-
-