diff options
Diffstat (limited to 'generic/tclEnv.c')
-rw-r--r-- | generic/tclEnv.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/generic/tclEnv.c b/generic/tclEnv.c index ef4e946..ef5cfb7 100644 --- a/generic/tclEnv.c +++ b/generic/tclEnv.c @@ -280,11 +280,11 @@ TclSetEnv( */ if ((env.ourEnviron != tenviron) || (length+2 > env.ourEnvironSize)) { - techar **newEnviron = (techar **)Tcl_Alloc((length + 5) * sizeof(techar *)); + techar **newEnviron = (techar **)ckalloc((length + 5) * sizeof(techar *)); memcpy(newEnviron, tenviron, length * sizeof(techar *)); if ((env.ourEnvironSize != 0) && (env.ourEnviron != NULL)) { - Tcl_Free(env.ourEnviron); + ckfree(env.ourEnviron); } tenviron = (env.ourEnviron = newEnviron); env.ourEnvironSize = length + 5; @@ -324,14 +324,14 @@ TclSetEnv( */ valueLength = strlen(value); - p = (char *)Tcl_Alloc(nameLength + valueLength + 2); + p = (char *)ckalloc(nameLength + valueLength + 2); memcpy(p, name, nameLength); p[nameLength] = '='; memcpy(p+nameLength+1, value, valueLength+1); p2 = utf2tenvirondstr(p, &envString); if (p2 == NULL) { /* No way to signal error from here :-( but should not happen */ - Tcl_Free(p); + ckfree(p); Tcl_MutexUnlock(&envMutex); return; } @@ -340,7 +340,7 @@ TclSetEnv( * Copy the native string to heap memory. */ - p = (char *)Tcl_Realloc(p, Tcl_DStringLength(&envString) + tNTL); + p = (char *)ckrealloc(p, Tcl_DStringLength(&envString) + tNTL); memcpy(p, p2, Tcl_DStringLength(&envString) + tNTL); Tcl_DStringFree(&envString); @@ -369,11 +369,20 @@ TclSetEnv( * This putenv() copies instead of taking ownership. */ - Tcl_Free(p); + ckfree(p); #endif /* HAVE_PUTENV_THAT_COPIES */ } Tcl_MutexUnlock(&envMutex); + + if (!strcmp(name, "HOME")) { + /* + * If the user's home directory has changed, we must invalidate the + * filesystem cache, because '~' expansions will now be incorrect. + */ + + Tcl_FSMountsChanged(NULL); + } } /* @@ -502,12 +511,12 @@ TclUnsetEnv( */ #if defined(_WIN32) - string = (char *)Tcl_Alloc(length + 2); + string = (char *)ckalloc(length + 2); memcpy(string, name, length); string[length] = '='; string[length+1] = '\0'; #else - string = (char *)Tcl_Alloc(length + 1); + string = (char *)ckalloc(length + 1); memcpy(string, name, length); string[length] = '\0'; #endif /* _WIN32 */ @@ -517,7 +526,7 @@ TclUnsetEnv( Tcl_MutexUnlock(&envMutex); return; } - string = (char *)Tcl_Realloc(string, Tcl_DStringLength(&envString) + tNTL); + string = (char *)ckrealloc(string, Tcl_DStringLength(&envString) + tNTL); memcpy(string, Tcl_DStringValue(&envString), Tcl_DStringLength(&envString) + tNTL); Tcl_DStringFree(&envString); @@ -538,7 +547,7 @@ TclUnsetEnv( * This putenv() copies instead of taking ownership. */ - Tcl_Free(string); + ckfree(string); #endif /* HAVE_PUTENV_THAT_COPIES */ } #else /* !USE_PUTENV_FOR_UNSET */ @@ -664,19 +673,8 @@ EnvTraceProc( if (flags & TCL_TRACE_WRITES) { const char *value; - Tcl_DString ds; value = Tcl_GetVar2(interp, "env", name2, TCL_GLOBAL_ONLY); - Tcl_DStringInit(&ds); - if (Tcl_UtfToExternalDStringEx(NULL, TCLFSENCODING, name2, -1, 0, &ds, NULL) != TCL_OK) { - Tcl_DStringFree(&ds); - return (char *) "encoding error"; - } - if (Tcl_UtfToExternalDStringEx(NULL, TCLFSENCODING, value, -1, 0, &ds, NULL) != TCL_OK) { - Tcl_DStringFree(&ds); - return (char *) "encoding error"; - } - Tcl_DStringFree(&ds); TclSetEnv(name2, value); TclEnvEpoch++; } @@ -750,7 +748,7 @@ ReplaceString( */ if (env.cache[i]) { - Tcl_Free(env.cache[i]); + ckfree(env.cache[i]); } if (newStr) { @@ -768,11 +766,11 @@ ReplaceString( const int growth = 5; - env.cache = (char **)Tcl_Realloc(env.cache, + env.cache = (char **)ckrealloc(env.cache, (env.cacheSize + growth) * sizeof(char *)); env.cache[env.cacheSize] = newStr; (void) memset(env.cache+env.cacheSize+1, 0, - (growth-1) * sizeof(char *)); + (size_t) (growth-1) * sizeof(char *)); env.cacheSize += growth; } } @@ -811,15 +809,15 @@ TclFinalizeEnvironment(void) #ifdef PURIFY Tcl_Size i; for (i = 0; i < env.cacheSize; i++) { - Tcl_Free(env.cache[i]); + ckfree(env.cache[i]); } #endif - Tcl_Free(env.cache); + ckfree(env.cache); env.cache = NULL; env.cacheSize = 0; #ifndef USE_PUTENV if ((env.ourEnviron != NULL)) { - Tcl_Free(env.ourEnviron); + ckfree(env.ourEnviron); env.ourEnviron = NULL; } env.ourEnvironSize = 0; |