Artifacts Associated With Ticket 34870ab5756911d1
Ticket change [9411eca5c4] (rid 227024) by chpock on 2024-05-30 16:41:27:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
tcl9.0 first call assocdata deletion callbacks, then release each data from hash after the callback, and then set iPtr->assocData to NULL when all assocdata is removed: [https://github.com/tcltk/tcl/blob/db5ec326417727be7fdfcfe92d15193c7d886648/generic/tclBasic.c#L1982-L1990](https://github.com/tcltk/tcl/blob/db5ec326417727be7fdfcfe92d15193c7d886648/generic/tclBasic.c#L1982-L1990) ``` if (iPtr->assocData != NULL) { AssocData *dPtr; hTablePtr = iPtr->assocData; /* * Invoke deletion callbacks; note that a callback can create new * callbacks, so we iterate. */ for (hPtr = Tcl_FirstHashEntry(hTablePtr, &search); hPtr != NULL; hPtr = Tcl_FirstHashEntry(hTablePtr, &search)) { dPtr = (AssocData *)Tcl_GetHashValue(hPtr); if (dPtr->proc != NULL) { dPtr->proc(dPtr->clientData, interp); } Tcl_DeleteHashEntry(hPtr); Tcl_Free(dPtr); } Tcl_DeleteHashTable(hTablePtr); Tcl_Free(hTablePtr); iPtr->assocData = NULL; } ``` In tcl8.6.14 the behavior was different: it first set iPtr->assocData to NULL, then for each assocData it removes hash entry, and after that invokes callback: [https://github.com/tcltk/tcl/blob/1d84e70c2decaf650f0f1a41b3de81bb0e19b58e/generic/tclBasic.c#L1539-L1550](https://github.com/tcltk/tcl/blob/1d84e70c2decaf650f0f1a41b3de81bb0e19b58e/generic/tclBasic.c#L1539-L1550) The difference in behavior leads to crash if assocdata deletion callback invokes Tcl_DeleteAssocData(). Tcl9 tries to call the callback, callback releases assocdata hash entry, then DeleteInterpProc() continues and releases the hash entry again. I don't see in documentation, that assocdata deletion callback must not call Tcl_DeleteAssocData(). Also, at least tclvfs is affected by this case: [https://github.com/chpock/tclvfs/blob/289dfa5ebf0c7374737c7a1fdef7103a0100b303/generic/vfs.c#L434](https://github.com/chpock/tclvfs/blob/289dfa5ebf0c7374737c7a1fdef7103a0100b303/generic/vfs.c#L434) - foundin initialized to: "9.0b2"
- is_private initialized to: "0"
- login: "chpock"
- priority initialized to: "5 Medium"
- private_contact initialized to: "fb0bef387a3d333f7502b23b2ca5bd198a1d1f87"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chpock"
- subsystem initialized to: "20. [interp]"
- title initialized to: "Double free of assocdata entry"
- type initialized to: "Bug"
Ticket change [e547fdaa94] (rid 227025) by sebres on 2024-05-30 18:32:51:
- foundin changed to: "8.7+"
- icomment:
Although I don't think it is good idea to invoke Tcl_DeleteAssocData from deletion callback (just an unneeded hash search), it looks indeed like an oversight: the issue going to [b95643fa3926f2e3] fixing loss of line (probably by conflict resolving) in [ec7e558c34856b07]. So it's safe to restore it back. <i>Again, a next illustration why a certain hygiene by space/spelling/line-length/whatever "fixing" is important and what pure artificial "fix" may cause in the long term. (I don't stop to repeat it.)</i> It affects 8.7 in the same way. I'll fix it now for 8.7+.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
Ticket change [4836fab667] (rid 227028) by sebres on 2024-05-30 18:39:33:
- closedate changed to: "2460461.27746551"
- closer changed to: "sebres"
- icomment:
Fixed in [0aedd271b215a880] and merged to 9.0. Thx for the report.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [ae00ea5aec] (rid 228653) by sebres on 2024-07-15 01:37:29:
- closedate changed to: "2460506.56770734"
- icomment:
The fix for that has a side effect detected in load library module (caused a memory leak, see [ae09f6b190ceec31]) due to improper free of assoc data in its clean-up proc. Moreover it looks like the full rewrite of LoadCleanupProc in 8.7+ (as well as UnloadLibrary) was previously implemented incorrectly for the case of interpreter deletion.<br/> Ultimately fixed in [24ace090aad63399].
- login: "sebres"
- mimetype: "text/x-fossil-wiki"