Overview
| Artifact ID: | e1880f0a4105031fa935906ae9e596d8c5fcd4b98858236d6a2c71e2cfbeefe5 |
|---|---|
| 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-11 16:46:03 |
Changes
- icomment:
> If you find code like this anywhere: > if (Tcl_ObjSetVar2(interp, varObj, NULL, newObj, 0) == NULL) {Tcl_DecrRefCount(newObj);} > ... > But that's the only bug I see. Well, this would be so, if the Tcl_ObjSetVar2 will get "ownership" for the object always, also in the error case. But, the problem is very, very serious, Don. Currently, Tcl_ObjSetVar "owns" object only in success-case, AND in error case, BUT then only if refCount is 0! AFTER the "failed" attempt of assignment, Don! So I see at least 2 issues here: 1) The function checks the refCount only AFTER trying of set the variable (which can change the refCount of the object by calling of the traces, etc). Much worse it looks just like undefined behavior. 2) For the developer using Tcl_ObjSetVar, it is very bad up to impossible to act plausible in error case, because he don't know when he should decrease refCount in error case or not, especially because the object can be released within Tcl_ObjSetVar, and then the developer has normally no chance to check the refCount (resp. the vitality of the object hereafter is unknown in error case). Thus either he do this nevertheless and can get segfault, or he produces intentionally a memory leak (quasi accepts the risk of possible leak). Additionally it is very confusing behavior for the function from public API in my understanding... Also if this will be "correctly" documented. In my opinion it is wrong so it is implemented. - login: "sebres"
- mimetype: "text/plain"