Skip to content
Tcl Source Code History Of Ticket 3386417fff
Login

History Of Ticket 3386417fff

Artifacts Associated With Ticket 3386417fff

  1. Ticket change [b613eaa37f] (rid 125362) by msofer on 2011-08-04 23:03:38:

    1. assignee initialized to: "ferrieux"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      When the compiler bails out on a syntax error, the errorstack is leaked. For example, for the script
      
        namespace eval x {set syntax {}{}}
      
      valgrind reports
      
      
        0:  malloc (vg_replace_malloc.c:236)
        1:  TclpAlloc (tclAlloc.c:705)
        2:  Tcl_Alloc (tclCkalloc.c:1046)
        3:  Tcl_NewListObj (tclListObj.c:225)
        4:  Tcl_CreateInterp (tclBasic.c:542)
        5:  Tcl_Main (tclMain.c:639)
        6:  main (tclAppInit.c:84)
      -- foo: ==9070== 3,248 (48 direct, 3,200 indirect) bytes in 1 blocks are definitely lost in loss record 136 of 136
      
      
    4. foundin initialized to: "obsolete: 8.6b2"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "msofer"
    10. subsystem initialized to: "47. Bytecode Compiler"
    11. title initialized to: "errorstack leaked on syntax error"
    12. type initialized to: "Bug"
  2. Ticket change [e27f6d2e11] (rid 87641) by ferrieux on 2011-08-06 17:46:32:

    1. assignee changed to: "msofer"
    2. icomment:
      Quick analysis shows that an extra ref (to errorstack, but also to other return options) is kept in an options-dict computed by CompileReturnInternal. That dict is soldered into a literal (TclAddLiteralObj), so it looks like the lifecycle of that literal is the culprit.
      
      
    3. login: "ferrieux"
    4. mimetype: "text/plain"
    5. username: "ferrieux"
  3. Ticket change [9a8dd6cfea] (rid 110965) by msofer on 2011-08-06 17:50:38:

    1. icomment:
      Unlikely: my valgrind script would show the literal or the options dict being leaked, but not the errorstack (as a ref to it would still be around, namely in the options dict). This is a 'definitely lost' struct ...
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  4. Ticket change [683e19203e] (rid 103030) by ferrieux on 2011-08-06 18:45:07:

    1. icomment:
      Good point :) So maybe that literal thing is a red herring. However, what is exactly your way of exiting Tcl so that all finalizations execute ? Are you using the 2919042 trick ? 
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  5. Ticket change [35b394048c] (rid 106984) by ferrieux on 2011-08-06 20:07:32:

    1. icomment:
      Cannot seem to repro with HEAD, even though patch 2919042 applied and TCL_FINALIZE_ON_EXIT set to 1, and single-line script with the above code passed as arg to non-interactive tclsh
      Note that valgrind --leak-check=full gives many other (larger) leaks, but not this one.
      
      Please give details about experimental conditions to help repro ;-)
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  6. Ticket change [278af2e4b0] (rid 88536) by msofer on 2011-08-06 21:45:00:

    1. icomment:
      Positively strange ...
      
      To repro
        CFLAGS=-DPURIFY ./configure --disable-shared --enable-symbols
      
      Then
      
      mig@ari:~/DEVEL/tcl-core/trunk/unix$ cat /tmp/foo
      namespace eval x {set syntax {}{}}
      proc exit args {}
      mig@ari:~/DEVEL/tcl-core/trunk/unix$ cat /tmp/foo | /usr/bin/valgrind --leak-check=yes --num-callers=10 --show-reachable=yes ./tcltest &> /tmp/foo.res
      
      Look for 'definitely' in /tmp/foo.res, you'll find it.
      
      BUT: the leak does NOT appear if you do
         /usr/bin/valgrind --leak-check=yes --num-callers=10 --show-reachable=yes ./tcltest /tmp/foo &> /tmp/foo.res
      So it may have something to do with io???
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  7. Ticket change [d0db4e5596] (rid 113257) by ferrieux on 2011-08-06 23:49:14:

    1. icomment:
      Hmm, I'd guess "interactive" is key. Though [history clear] was not enough to purge the offending literal in my tests. Will dig further.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  8. Ticket change [9e65f2384c] (rid 96465) by ferrieux on 2011-08-07 00:06:31:

    1. icomment:
      By the way, though you're not telling, I guess you are using the patch from 2919042 (so that -DPURIFY forces finalization), right ? Since it seems useful for leak hunting, how about a commit ?
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  9. Ticket change [a7e9842cec] (rid 98879) by ferrieux on 2011-08-07 00:21:05:

    1. icomment:
      Sorry to push ahead with even more tangents.. but in my case:
       - with 2919042 's val4.patch and CLFLAGS=-DPURIFY, I do get the errorStack leak regardless of the kind of script passing method (stdin via <, stdin via pipe, or tclsh single arg).
      
      - with val4.patch and no PURIFY, but just TCL_FINALIZE_ON_EXIT=1, I get many "possibly lost" but no "definitely lost", regardless of the script disposition.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  10. Ticket change [ce7eae230e] (rid 96068) by msofer on 2011-08-07 04:17:37:

    1. icomment:
      not using the patch here
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  11. Ticket change [96087605cd] (rid 106247) by ferrieux on 2011-08-07 18:09:12:

    1. icomment:
      Ah, ok !
      Also note that your "proc exit args {}" is ineffective when placed after the barfing [namespace eval] ;-)
      So basically, two things are equivalent regarding this leak, once -DPURIFY is set:
        - apply the patch
        - redefine exit (and do it before erroring out ;-)
      However, with either method I cannot reproduce the difference between stdin and arg script. In both cases I do get the "definitely lost".
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  12. Ticket change [64eb4dbdc9] (rid 92857) by ferrieux on 2011-08-07 18:33:30:

    1. icomment:
      Anyhow, I'm still wondering about literals' end of life. A watchpoint on the options dict object's refcount shows it never goes below 1, nor is TclReleaseLiteral called on it. Could it be subject to a kind of "fast erasure" that would deplete its hashtable behind the scenes ?
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  13. Ticket change [cf7cbd36c2] (rid 112986) by msofer on 2011-08-07 19:54:22:

    1. icomment:
      Redefining exit before the error (good catch, thx!) now shows the leak here in all script-input modes. Ie, not the same that you are seeing ...
      
      Another funny observation: replacing 'namespace eval x' with 'if 1' (both insuring bcc'ing) removes the leak too.
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  14. Ticket change [d7d01d004f] (rid 107329) by ferrieux on 2011-08-08 00:36:05:

    1. icomment:
      Hum, it turns out that hashtable values are stored in the "clientData" field of Tcl_HashEntry, with a cast (to void* or int*)... I dunno how smart Valgrind is about casts, but could a pointer type mismatch block its path-walking ?
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  15. Ticket change [b44dafb799] (rid 125005) by ferrieux on 2011-08-08 01:59:58:

    1. icomment:
      To clarify: I'm aware that a type cast is a source-level abstraction, and that all pointers are machine words.. but not sure of the amount of type info that -g brings into the executable. Pulling at straws...
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  16. Ticket change [20c7176632] (rid 130474) by dkf on 2011-08-08 19:57:01:

    1. icomment:
      I'd guess that the problem is elsewhere; Valgrind's really operating on machine words (it's a machine-code-level annotation tool applied to memory analysis). I've seen times when I thought it was a problem in valgrind and where it turned out to be somewhere else _in my code_ than the place I expected. I'm resigned to such things these days, but it's one of these hard-to-believe got-to-see-it-for-yourself matters...
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  17. Ticket change [a86ed1e5b0] (rid 98993) by ferrieux on 2011-08-09 05:44:58:

    1. icomment:
      OK, got it: what we are witnessing is a cycle in the reference graph. Indeed errorstack is special in that it records, as true references, all the command lines in the stack, including the [namespace eval x OFFENDINGSCRIPT]. As a consequence:
          - options(-errorstack) holds a reference to OFFENDINGSCRIPT
          - OFFENDINGSCRIPT's BC holds, as a literal, a reference to options()
      Cycle.
      
      So, the reason why TclCleanupByteCode is not called on the syntax error, is the above cycle.
      So the whole cycle gets unreachable, and valgrinds just selects one as "definitely lost" and the rest as "indirectly lost".
      
      The cure is simply to remove the (compile-time) errorstack from the options dict when processing a syntax error.
      Patch to follow. 
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  18. Add attachment "errorstackloop.patch" [bc41c0ced7] (rid 101719) by ferrieux on 2011-08-09 06:13:20.

  19. Ticket change [872d87b783] (rid 131648) by ferrieux on 2011-08-09 06:13:21:

    1. icomment:
      
      
      File Added - 420603: errorstackloop.patch
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  20. Ticket change [03d613f799] (rid 119891) by ferrieux on 2011-08-10 00:03:00:

    1. icomment:
      Committed to HEAD after a quick chat.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  21. Ticket change [0556bb83ab] (rid 89044) by ferrieux on 2011-08-10 00:03:01:

    1. closedate changed to: "2011-08-09T17:03:01"
    2. closer changed to: "ferrieux"
    3. resolution changed to: "Fixed"
    4. status changed to: "Closed"
  22. Ticket change [de3602ee56] (rid 114805) by ferrieux on 2011-08-11 04:40:31:

    1. icomment:
      As a post-bug-mortem comment: I wrote a page on the wiki summarizing all I've learnt while solving this one:
      
           Leak Hunt (C level)
           http://wiki.tcl.tk/28634
      
      it also gives the basic 'valgrind recipe' and mentions the --enable-symbols=all pitfall dgp observed
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"