[Tcl-bugs] [Tcl] (sebres) tkt (Open): Very rare bug (segfault) if set variable (with error case) using self-releasable object as new value

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Tcl-bugs] [Tcl] (sebres) tkt (Open): Very rare bug (segfault) if set variable (with error case) using self-releasable object as new value

akupries
Automated mail by fx, on behalf of [hidden email]

Ticket Change [6183532f3e2e19116a12f43e2049f9d35204d6d8]
  [Very rare bug (segfault) if set variable (with error case) using self-releasable object as new value]
  By      sebres
  For     Tcl
  On      2017-07-12T20:04:15.019
  Details https://core.tcl.tk/tcl/tinfo?name=6183532f3e2e19116a12f43e2049f9d35204d6d8
  Ticket  https://core.tcl.tk/tcl/tktview/578155d5a19b348dc1a9fe96cc2c067a59326a89

Changed Fields
  icomment: Although the emphasis was "only once" referenced, but it is not always
            the case: the object newValue can be referenced twice or more
            (newValue->refCount > 1) and described situation can nevertheless
            still occur, if we've something like this:  <code><pre>  set X [list
            [list 1st-list $newValue] [list 2nd-list $newValue] ...]
            call-something-that-set-var ::missing::namespace::var
            [call-something-unset-X-and-return-its-value X]  </pre></code>  I
            think this example describes the issue very good.

            Thus my proposal to solve it (resp. to workaround it) using:
            <pre><code>  <b style="color:green">+ int freeNewVal =
            (newValuePtr->refCount == 0);</b>

            part1 = TclGetString(part1Ptr);  part2 = ((part2Ptr == NULL) ? NULL :
            TclGetString(part2Ptr));

            varPtr = TclObjLookupVar(interp, part1Ptr, part2, flags, "set",
            /*createPart1*/ 1, /*createPart2*/ 1, &arrayPtr);  if (varPtr == NULL)
            {  <b style="color:red">- if (newValuePtr->refCount == 0) {</b>  <b
            style="color:green">+ if (freeNewVal) {</b>
            Tcl_DecrRefCount(newValuePtr);  }  return NULL;  }  </code></pre>
  login:    sebres

------------------------------------------------------------
See Tcl/Tk development @ http://core.tcl.tk/
------------------------------------------------------------

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Bugs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-bugs
Loading...