"unload" command Bug (when handling multiple libs)
Closed / Fixed8cd2fe747463756f4a4a31f726c2c0163ecde2ffCreated 7 years agoUpdated 7 years ago
Descriptionplain2019-11-12 09:57:52
In tclLoad.c (i.e. https://core.tcl-lang.org/tcl/artifact/76192e755eed7560) there is a bug which occurs when a library is unloaded.
In the part "Remove this library from the interpreter's library cache.", the next pointers of the linked list are not properly updated.
ipFirstPtr = Tcl_GetAssocData(target, "tclLoad", NULL);
ipPtr = ipFirstPtr;
if (ipPtr->pkgPtr == defaultPtr) {
ipFirstPtr = ipFirstPtr->nextPtr;
} else {
InterpPackage *ipPrevPtr;
for (ipPrevPtr = ipPtr; ipPtr != NULL;
ipPrevPtr = ipPtr, ipPtr = ipPtr->nextPtr) {
if (ipPtr->pkgPtr == pkgPtr) {
ipPrevPtr->nextPtr = ipPtr->nextPtr;
break;
}
}
}
should be
ipFirstPtr = Tcl_GetAssocData(target, "tclLoad", NULL);
ipPtr = ipFirstPtr;
if (ipPtr->pkgPtr == defaultPtr) {
ipFirstPtr = ipFirstPtr->nextPtr;
} else {
InterpPackage *ipPrevPtr;
for (ipPrevPtr = ipPtr; ipPtr != NULL;
ipPrevPtr = ipPtr, ipPtr = ipPtr->nextPtr) {
if (ipPtr->pkgPtr == defaultPtr) {
ipPrevPtr->nextPtr = ipPtr->nextPtr;
break;
}
}
}
So the check "(ipPtr->pkgPtr == pkgPtr)" should really be "(ipPtr->pkgPtr == defaultPtr)"
With this bug, one can get error messages when first unloading a lib (works properly) and then unloading another one (will return error "has never been loaded in this interpreter" because it cannot be find in the list, because the linked list has been corrupted.
Referenced by3
29086fe087Fix [8cd2fe7474]: "unload" command Bug (when handling multiple libs) check-in2020-01-17 08:53:298f93f9da3cFix [8cd2fe7474]: "unload" command Bug (when handling multiple libs) check-in2020-01-17 08:51:38e582dc6e06Proposed fix for [8cd2fe7474]: "unload" command Bug (when handling multiple libs) check-in2020-01-16 14:16:48
dgp Ticket [8cd2fe7474]: 5 changes
[History diff]2019-11-13 15:06:49
jan.nijtmansplain2020-01-16 14:18:00
Proposed fix committed to bug-8cd2fe7474 branch. Looks good. Thanks for the report and fix. I'll do some testing first.
jan.nijtmansplain2020-01-17 09:22:31
Fixed in all branches. Thanks!
Log in (anonymous is fine) to add a comment.