Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 759e2f5cf21ff4e99c78400dd4a6633389b464a5
Ticket: 623269ffffffffffffffffffffffffffffffffff
mem leak in Tcl_PutEnv.
User & Date: hobbs on 2002-10-14 22:20:33
Changes

  1. assignee changed to: "hobbs"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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. 
    
    
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "hobbs"
  9. subsystem changed to: "08. Environment Variables"
  10. title changed to: "mem leak in Tcl_PutEnv."
  11. type changed to: "Patch"