From c732fecaa0babcee5b1a681696d9366d226d6849 Mon Sep 17 00:00:00 2001 From: hobbs Date: Wed, 13 Oct 1999 00:32:16 +0000 Subject: * generic/tclEnv.c: fixed mem leak with putenv and DStrings --- generic/tcl.h | 3 ++- generic/tclEnv.c | 36 +++++++++++++++--------------------- 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 } } - - - - -- cgit v0.12