Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: fe01f173f487fcfcde4b1876199fd75462c0b1a3f1428ee6e70fb38c3a580980
Ticket: 6d4e9d1af5bf5b7dc8c359c2c169974c0b963066
memory leak: SetFsPathFromAny, assisted by the global literal table, causes a Tcl_Obj to reference itself
User & Date: pooryorick on 2023-03-26 10:30:33
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    [https://core.tcl-lang.org/tcl/file?udc=1&ln=2359&ci=c02747a663bc158a&name=generic%2FtclPathObj.c|SetFsPathFromAny]
    duplicates a Tcl_Obj and then stores a pointer to the new object in a
    fsPathPtr, which it then sets as the internal representation of another
    Tcl_Obj, pathPtr.  Because no care is taken to ensure that the internal
    representation of the newly-duplicated Tcl_Obj contains no reference-counted
    copy of pathPtr, it's possible for a situation to arise where pathPtr contains
    a pointer to itself, and that its reference count therefore never drops to 0,
    which is a memory leak.
    
    In test Tcl_Main-2.1 such a situation does in fact occur:  "result" is a
    literal value that, by the time SetFsPathFromAny receives it, has already been
    entered into the literalTable of the interpreter, and has also received an
    internal representation of type "localVarNameType", possibly due to its
    appearance in procedures within msgcat.tcl.  When pathPtr is duplicated,
    DupLocalVarName()
    [https://core.tcl-lang.org/tcl/file?udc=1&ln=5809&ci=c02747a663bc158a&name=generic%2FtclVar.c|makes
    pathPtr the internal representation of the duplicated object], transPtr.  Then
    transPtr is stored in fsPathPtr, which becomtes the internal representation of
    pathPtr.  Valgrind reports still-reachable blocks due to this situation, but
    only when all other tests are deleted from the source file.
    
    Although this issue can be fixed by modifying SetFsPathFromAny, it is yet
    another example of how sharing a single Tcl_Obj between identical literal
    values causes trouble.  First, it creates a situation where there is only one
    internal representation even though the identical literal values may have
    different contexts and interpretations.  Second, it makes errors like this one,
    which can go undiscovered for years, more likely.
    
  5. is_private changed to: "0"
  6. login: "pooryorick"
  7. priority changed to: "5 Medium"
  8. private_contact changed to: "2b2275eab1118e1fab0016cf1c5702893c6af86c"
  9. resolution changed to: "None"
  10. severity changed to: "Critical"
  11. status changed to: "Open"
  12. submitter changed to: "pooryorick"
  13. subsystem changed to: "36. Pathname Management"
  14. title changed to:
    memory leak:  SetFsPathFromAny, assisted by the global literal table, causes a Tcl_Obj to reference itself
    
  15. type changed to: "Bug"