Skip to content
Tcl Source Code History Of Ticket 886231ffffffffff
Login

History Of Ticket 886231ffffffffff

Artifacts Associated With Ticket 886231ffffffffff

  1. Ticket change [8900860a19] (rid 131960) by nobody on 2004-01-28 14:37:17:

    1. assignee initialized to: "hobbs"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      testing a references support for Tcl I'm developing
      (that will be
      the subject of another comunication), I discovered a
      bug that
      is very common in languages implementations using
      reference counts.
      
      The problem is that when a reference of an object drops
      to zero,
      the Tcl_DecrRefCount() calls Tcl_FreeObj() in order to
      free the
      object internal representation, string, and storage
      allocation.
      If that object is able to take references to other
      objects, before
      to free the object, all the referenced objects gets
      RefDecremented(),
      and this can result in a new (recursive) invocation of
      Tcl_FreeObj().
      
      That's how it should be in theory, but with deeply
      nested data
      structures, for example lists containing lists
      containing lists (...)
      the result is a deep recursion of Tcl_FreeObj(), and
      once the C
      stack is terminated, a segmentation fault.
      
      The following code will crash Tcl on many operating systems
      and many archs:
      
      set x foobar
      time {lset x 0 [list $x 2]} 20000
      set x {}
      
      If this is not able to crash your box, try with a value
      a bit
      bigger than 20000.
      
      Another way to crash Tcl is to substitute the "set x
      {}" final
      command with "string length $x". Because the list -> string
      conversion also is a recursive call.
      
      Of course the 'free' problem is much severe than the string
      conversion one, but fortunatelly the fix is general and
      quite
      simple.
      
      To fix this problem Tcl should "lazy free" objects.
      Instead to really
      free the object, Tcl_FreeObj() should just put the
      object's pointer
      in a ToFree list, then free that list only when
      Tcl_FreeObj() is
      not called recursively (an alternative is to call a
      Tcl_FreeCycle()
      when there is some allocation action, and on low memory).
      
      I did a simple implementation for Tcl HEAD (attached to
      this email).
      Seems to work well but should be modified to support
      threads
      and the Tcl coding style.
      
      Regards,
      Salvatore Sanfilippo
      
    4. foundin initialized to: "None"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "41. Memory Allocation"
    10. title initialized to: "Tcl interpreter does not lazy-free objects."
    11. type initialized to: "Bug"
  2. Ticket change [a2b1d43734] (rid 109940) by nobody on 2004-01-28 21:37:18:

    1. icomment:
      
      
      File Added - 74990: lazyfree.patch
      
      
      
    2. login: "nobody"
    3. mimetype: "text/plain"
    4. username: "nobody"
  3. Add attachment "lazyfree.patch" [8ab0035bd0] (rid 127433) by nobody on 2004-01-28 21:37:18.

  4. Ticket change [381721ddc8] (rid 112145) by hobbs on 2004-02-04 07:31:47:

    1. priority changed to: "7 High"
  5. Ticket change [99eeafda2a] (rid 110876) by hobbs on 2004-05-04 05:44:44:

    1. assignee changed to: "dkf"
    2. icomment:
      Logged In: YES 
      user_id=72656
      
      IIRC dkf was looking into this at one point.
      
      
    3. login: "hobbs"
    4. mimetype: "text/plain"
    5. username: "hobbs"
  6. Ticket change [43d2b8bdd7] (rid 116623) by dkf on 2004-05-04 16:24:14:

    1. foundin changed to: "obsolete: 8.4.6"
    2. icomment:
      Logged In: YES 
      user_id=79902
      
      I looked and saw that it was indeed a problem.  :^)
      
      The fix is to be careful about nested calls to TclFreeObj()
      but I'd need to check whether antirez's patch adds
      additional overhead in terms of locking in threaded builds
      (ideally, single level frees will happen immediately, but
      multi-level frees will be queued; current behaviour is to
      process them using the stack, which unsurprisingly blows up.)
      
      If I don't review and fix this by the next release, moan at me.
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. priority changed to: "8"
    6. username: "dkf"
  7. Ticket change [1fa7a9bddb] (rid 91186) by dkf on 2004-05-06 03:23:00:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      The supplied patch is not even close to thread-safe.  :^/
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  8. Ticket change [c2da242293] (rid 111554) by dkf on 2004-05-06 03:24:57:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      Just wondering if it would be possible to build a queue
      using the bytes field to hold the links between objects
      being freed?
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  9. Ticket change [5b380e0e8d] (rid 118281) by msofer on 2004-05-07 22:08:28:

    1. icomment:
      Logged In: YES 
      user_id=148712
      
      Some notes:
      
      1. It is probably necessary to arrange that the objs are
      really freed in the same order of the requests. This is no
      guarantee that things will work, but is more robust than
      inverting the order wrt assumptions by extensions. IOW, we
      need a queueToFree (FIFO) - not a stackToFree
      
      2. Each object should be freed from its own thread. This
      implies that each thread has to maintain its own queue, even
      if using the non-threaded allocator with a unified
      tclFreeObjList.
      
      3. The "laziest" approach (free the object when it is about
      to be reused) could be dangerous: an extension may be
      keeping a reference to the obj that is not accounted in the
      refCount, relying on the freeIntRepProc to remove it. If we
      delay calling fIRP while the obj is in fact dead for tcl,
      the extension is not notified of this death and could reuse
      it - not good.
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  10. Ticket change [7d85c21220] (rid 97255) by dkf on 2004-06-15 04:42:29:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      I have a prototype fix for this in the works.  A few
      comments on Miguel's notes:
      1. Queues are more complex to maintain than stacks, and
      library code tidying up the guts of a type should
      categorically not rely on the order of deletion of objects.
      The core does not document what this order is BTW.
      2. The behaviour (whether or not to use per-thread
      collecting) depends purely on TCL_THREADS and not which
      allocator. It turns out that this can be done really neatly
      with virtually the same code in the threaded and
      non-threaded case. :^)
      3. Being very lazy is probably not a good idea, especially
      as it will significantly increase the overall memory
      consumption of Tcl unless a strategy of "reuse the most
      recently released object" is used, which negates a lot of
      the benefit of laziness.  Keeping a reasonable degree of
      openness is best.
      
      I'll upload the patch once I've got a version which compiles
      cleanly in both threaded and non-threaded builds. ;^)
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  11. Ticket change [2b28f9cd38] (rid 118690) by dkf on 2004-06-16 21:27:58:

    1. assignee changed to: "msofer"
    2. icomment:
      Logged In: YES 
      user_id=79902
      
      Here's the changes I had in mind.  The patch should be
      neatly thread-safe (make test in threaded Tcl works) and
      appears to deal with the freeing problem firmly (or at least
      when I have a go with an object tree ten times deeper than
      the fault was reported for, nothing goes wrong. :^)
      
      Assigning to area maintainer for review.
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. username: "dkf"
  12. Ticket change [f6090658d3] (rid 130222) by dkf on 2004-06-16 21:27:59:

    1. icomment:
      
      
      File Added - 90857: freeobj.diff
      
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  13. Add attachment "freeobj.diff" [4bc1467c80] (rid 126763) by dkf on 2004-06-16 21:40:55.

  14. Ticket change [d1654f60c9] (rid 113338) by dkf on 2004-06-16 21:40:56:

    1. icomment:
      
      
      File Added - 90859: freeobj.diff
      
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  15. Ticket change [39a7c36259] (rid 112428) by dkf on 2004-06-16 21:40:57:

    1. icomment:
      
      
      File Deleted - 90857: 
      
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  16. Ticket change [3528bd0607] (rid 106874) by dkf on 2004-06-18 22:14:01:

    1. assignee changed to: "dkf"
    2. icomment:
      Logged In: YES 
      user_id=79902
      
      Fixed in HEAD and added tests.
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. resolution changed to: "Fixed"
    6. status changed to: "Closed"
    7. username: "dkf"
  17. Ticket change [f8fb8ce4db] (rid 91633) by dkf on 2004-06-18 22:14:02:

    1. closedate changed to: "2004-06-18T15:14:02"
    2. closer changed to: "dkf"