Overview
| Artifact ID: | b72e6a29e305de82b16061b7f92bad062c03f2fa |
|---|---|
| Ticket: | 1334947fffffffffffffffffffffffffffffffff
refCounts on PtrSetVar failure |
| User & Date: | msofer on 2005-10-22 15:25:12 |
Changes
- assignee changed to: "dgp"
- cmimetype changed to: "text/plain"
- comment changed to:
The refCount management of TclPtrSetVar, and also its different "front ends" in tclVar.c, presents one particular problem which was revealed by [Bug 1191369] (both 8.4 and 8.5 are concerned). The problem arises when the newValuePtr obj has refCount 0: (1) if setting the new value succeeds as requested, newValuePtr gets its refCount incremented to reflect the new reference (2) if setting the new value fails early (eg, trying to set an array to a scalar value), newValuePtr's refCount is not touched (3) If there is a write trace that does not allow the value to be set as requested, newValuePtr's refCount will be incremented/decremented, resulting in it being freed. This renders the caller's refCount management rather critical, as reflected in 1191369. There are other spots in the core where a similar bug is present. Example: Tcl_AddObjErrorInfo would leak an obj if errorCode or errorInfo redefined to be arrays (I know, well deserved); Tcl_Main would leak if "argc" was an array. Worse, witness (in a MEM_DEBUG HEAD): % trace add variable a write {return -code error "RO var";#} % regexp qw qwerty -> a couldn't set variable "a" % set a file = ../generic/tclExecute.c, line = 2099 Trying to increment refCount of previously disposed object. There are two possible fixes: (a) fix all callers so that they incr before calling, decr on return. Add a warning in the docs. (b) fix TclPtrSetVar so that it does incr/decr for all paths where it fails to set the value as requested, allowing the callers to delegate the refCount management to TclPtrSetVar. The callers still have to be fixed to not touch that refCount. I have a preference for (b); assigning to dgp as a request for opinion. Please comment and assign back. - foundin changed to: "obsolete: 8.4.11"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "msofer"
- subsystem changed to: "07. Variables"
- title changed to: "refCounts on PtrSetVar failure"
- type changed to: "Bug"