Skip to content
Tcl Source Code View Ticket
Login

View Ticket

mem leak in Tcl_PutEnv.

Closed / Fixed623269ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2002-10-14 22:20:33
From Jean Brouwers mrjean1 -> earthlink.net

There is a memory leak in function Tcl_PutEnv() in file 
generic/tclEnv.c in 8.3.4 and earlier.  Haven't checked 
later versions.

The leak does only occur under specific conditions*.  
Here is an improved implementation for that function.

int
Tcl_PutEnv(string)
    CONST char *string;/* Info about 
environment variable in the
 * form 
NAME=value. (native) */
{
    Tcl_DString nameString;
    char *name, *value;

    if (string == NULL) {
return 0;
    }

    /*
     * First convert the native string to UTF.  Then 
separate the
     * string into name and value parts, and call 
TclSetEnv to do
     * all of the real work.
     */

    name = Tcl_ExternalToUtfDString(NULL, string, -1, 
&nameString);
    value = strchr(name, '=');

    if (value != NULL && value != name) {
value++ = '\0';
TclSetEnv(name, value);
    }

    Tcl_DStringFree(&nameString);
    return 0;
}

/Jean Brouwers

*) In the original code, Tcl_DStringFree(&nameString) is 
not called if the input string does not contain a '=' or if 
the first character is '='.  A memory leak will occur if 
string is large enough that additional memory was 
allocated for nameString.
hobbsplain2002-10-15 05:23:26
Logged In: YES 
user_id=72656

fixed for 8.3.5 and 8.4.1.
Log in (anonymous is fine) to add a comment.