Overview
| Artifact ID: | 20dd8a47a1e6c7e0dbf6976a36def2ddb292ae8f |
|---|---|
| Ticket: | 2629338fffffffffffffffffffffffffffffffff
segfault on traced vars in TclCallVarTraces |
| User & Date: | dgp on 2014-10-09 14:14:42 |
Changes
- closedate changed to: "2456940.09354546"
- closer changed to: "dgp"
- comment changed to:
I've had a bug preventing me from upgrading my product to 8.5 for some time, but I've never been able to narrow it down to a simple example. So, In lieu of that, here's a patch that fixes the bug. The issue is commonly triggered by tdom, which makes extensive use of variable traces (well, one per dom object.) The core issue is essentially that TclUnsetVarStruct calls all the unset traces on the variable, then sets about deleting the traces. The problem is, the traces may have already deleted themselves when they were called. (which tdom's always do.) In particular, the 'head' of the list may have removed itself. In that case, TclUnsetVarStruct starts iterating over the items to be freed while looking at already-freed memory. Since it was freed so recently, it gets away with this in the normal case, but on rare occasions, the memory has already been reallocated. Hilarity ensues. I'm not sure if this counts as the same bug or not, but TclDeleteNamespaceVars neglects to update the nextTracePtr for the activeVarTracePtr on the interp, with similar results. I've never seen that bug trigger anywhere but windows, but it shows up fairly often there in our product (on tcl 8.4.13 as well as 8.5.6.) I also noticed that the VarTrace entries are freed with 'Tcl_EventuallyFree' without updating their next pointers. Since another call might have the current object preserved, but not the next one, the current object might stick around and continue being used while the next object has already been freed. So the patch includes a change to null out the next pointer when calling eventuallyfree. I'm not sure if there's a user-visible bug associated with that or not. I did a cursory check for similar antipatterns in other files for var traces (and found none) but didn't bother checking other link lists. I will attach the patch.
- login: "dgp"
- mimetype: "text/plain"
- severity changed to: "Minor"
- status changed to: "Closed"