Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 45d7ecdda1c3246e38ec1800659a6d16ca24937f
Ticket: 219112ffffffffffffffffffffffffffffffffff
missing Tcl_DStringFree() in win/tclWinPipe.c (very simple)
User & Date: nobody on 2000-10-26 01:10:58
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 6041 Bug
    Version: 8.3.1
    SubmitDate: '2000-07-24'
    LastModified: '2000-07-25'
    Severity: MED
    Status: Released
    Submitter: techsupp
    ChangedBy: ericm
    OS: All
    FixedDate: '2000-07-25'
    FixedInVersion: 8.4a2
    ClosedDate: '2000-07-24'
    
    
    Name:
    
    marc herbert
    
    
    ReproducibleScript:
    
    Simple Tcl_DStringFree() call missing
    
    Possible memory leak
    
    Patch self-explanatory
    
    
    Patch:
    
    ===================================================================
    
    RCS file: RCS/tclWinPipe.c,v
    
    retrieving revision 1.1
    
    diff -c -r1.1 tclWinPipe.c
    
    *** tclWinPipe.c        2000/07/24 09:38:53     1.1
    
    --- tclWinPipe.c        2000/07/24 09:41:09
    
    ***************
    
    *** 1569,1574 ****
    
    --- 1569,1575 ----
    
                Tcl_DStringAppend(&ds, "\"", 1);
    
            }
    
          }
    
    +     Tcl_DStringFree(linePtr);
    
          Tcl_WinUtfToTChar(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds), linePtr);
    
          Tcl_DStringFree(&ds);
    
      }
    
    
    PatchFiles:
    
    win/tclWinPipe.c
    
    
    
    
    I don't think that this modification is necessary; the DString referred to as linePtr in the function indicated above is managed by the calling function, not by BuildCommandLine itself.  See the function TclpCreateProcess, at line 1232 of tclWinPipe.c.  The DString is free'd at that point.
    
       Eric Melski                            The Other Tcl Guy
       ericm at ajubasolutions.com            Ajuba Solutions
    
    -- 07/24/2000 ericm
    
    Éric,
    
    I think you're wrong. Let's see the Tcl man pages :
    
    >      Tcl_DStringInit initializes a dynamic string to zero
    >      length. The Tcl_DString structure must have been allocated by
    >      the caller. No assump­ tions are made about the current
    >      state of the structure; anything already in it is discarded.
    
    And in particular :
    
    >      If the structure has been used previously, Tcl_DStringFree
    >      should be called first to free up any memory allocated for the
    >      old string.
    
    This is because a "brutal" Tcl_DStringInit () may leave the possibly
    already dynamic allocated memory unreferenced.
    
    => garbage, memory leak.
    
    The Tcl_DStringFree () you mention (tclWinPipe.c:1232) is too late. A
    "brutal" Tcl_DStringInit () has occured before, thanks to the
    Tcl_WinUtfToTChar() call seen in my patch just above.
    
    --------------------
    
    In short :
    BuildCommandLine () gets a arguments already initialized (we both
    agree on that point) :
    
    static void
    BuildCommandLine(
         ...
        Tcl_DString *linePtr)       /* Initialized Tcl_DString that receives the
                                     * command line (TCHAR). */
    )
    
    But it does a second "over-Tcl_DStringInit ()" on it, via
    Tcl_WinUtfToTChar(), without freeing it first, and this is wrong.
    
    Sincerely,
    
    -- 
    Marc Herbert             | GIE Dyade (Bull/INRIA)
    [email protected]    |   http://www.dyade.fr/
    tel: +33 4 7661 5258   | VASY Project 
    fax: +33 4 7661 5252   |   http://www.inrialpes.fr/vasy
    
    ----
    
    Yes, you are right.  Thanks for straightening me out.  I've applied your patch and committed it to CVS.  The fix will be included in Tcl 8.4a2.
    
       Eric Melski                            The Other Tcl Guy
       ericm at ajubasolutions.com            Ajuba Solutions
    
    -- 07/25/2000 ericm
    
    
    
  4. foundin changed to: "obsolete: 8.3.1"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to:
    missing Tcl_DStringFree()  in win/tclWinPipe.c (very simple)
    
  11. type changed to: "Bug"