Overview
| Artifact ID: | e6e05669294a8ddd2ddbeea10efc1c7ce51dae2182b039e96fa6e17333adb748 |
|---|---|
| Ticket: | 578155d5a19b348dc1a9fe96cc2c067a59326a89
Very rare bug (segfault) if set variable (with error case) using self-releasable object as new value |
| User & Date: | sebres on 2018-01-16 12:19:12 |
Changes
- icomment:
Append to my previous comment... As reragds the new flag TCL_OWN_OBJREF - it should say the Tcl_ObjSetVar2, that the object should be owned to the variable. So Tcl_ObjSetVar2 DOES NOT increase refCount in success case and should ALWAYS decrease the refCount in error case. Emphasis on ALWAYS (and not just in case of no references after failed assignment). So both codes from my previous comment will look like: 1. Transmit "ownership" of reference to variable (** don't touched in success, -1 in error case): ``` int X1 (Tcl_Obj *varName, Tcl_Obj *objPtr, ...) { if (Tcl_ObjSetVar2(interp, varName, NULL, objPtr, flags | TCL_OWN_OBJREF)) == NULL) { /* Handle error ... */ return TCL_ERROR; } } ``` 2. New reference with variable (** +1 if success, don't touched in error case): ``` int X2 (Tcl_Obj *varName, Tcl_Obj *objPtr, ...) { if (Tcl_ObjSetVar2(interp, varName, NULL, objPtr, flags & ~TCL_OWN_OBJREF)) == NULL) { /* Handle error ... */ return TCL_ERROR; } } ``` That's it. In this case all internal calls that submit new created object could be: - either extended with `flags | TCL_OWN_OBJREF` - or additionally the "obscure" hack with auto-decrement in the error case will remain, but should be then definitely rewritten as suggested in branch fix-8-5-578155d5a19b348d] (see [bc5e7bdafc]). The second way (auto-decrement in error case on refCount==0) is admittedly backwards-compatible, but IMHO not good in the long term, also if it will be documented as precise as possible. - login: "sebres"
- mimetype: "text/plain"