Overview
| Artifact ID: | 392a22a4e780afb635dfef60a88396cb60363e6178ea7ceb07e95c2dec2db6d2 |
|---|---|
| Ticket: | 578155d5a19b348dc1a9fe96cc2c067a59326a89
Very rare bug (segfault) if set variable (with error case) using self-releasable object as new value |
| User & Date: | dgp on 2018-01-11 15:56:32 |
Changes
- icomment:
If you haven't already seen it, the history of the purpose of the interface change in Tcl_ObjSetVar2() between 8.4 and 8.5 is here https://core.tcl.tk/tcl/tktview/1334947 It was not until much later that the corresponding change to Tcl_SetVar2Ex() was completed properly. https://core.tcl.tk/tcl/tktview/7368d225a6 In 8.4 it was impossible to call the variable setting routines in a way that could fully reliably prevent memory leaks. Error paths from failed lookup were inconsistent with error paths from traces. It was an unusable interface. For 8.5, the refcount behavior of the variable setting routines was changed to what it is now. These routines now act as Consumers of the "newValuePtr" argument. Effectively they always incr the refCount, and promise to eventually decr it. If you pass in a 0 ref count newly created value, this scheme will not leak it. That's the most convenient way to use these routines. It is possible the newValuePtr will be freed before the variable setting routine returns. If the caller has a need to use that value after the variable setting routine returns, it needs to explicitly make its own incr of the refcount to preserve the value and its own balancing decr. If you find code like this anywhere: Tcl_Obj *newObj = Tcl_NewObj(); if (Tcl_ObjSetVar2(interp, varObj, NULL, newObj, 0) == NULL) { Tcl_DecrRefCount(newObj); return TCL_ERROR; } It is an outdated attempt to code to the 8.4 interface. It must be changed to work properly with Tcl 8.5 and later. See for example, http://core.tcl.tk/tk/tktview?name=3607326 I agree the documentation of this is not good enough. But that's the only bug I see. If I'm missing some scenario where that's not addressing something important, I'm afraid I'm going to need a concrete demonstration (not a description. Something I can run) to see it. Best I can tell only a misbehaving variable resolver can cause trouble, and in that case the remedy would be to make that resolver behave. - login: "dgp"
- mimetype: "text/plain"