Ticket UUID: | 28027d8bb7745fb053954276bb62aa4d6e340b16 | |||
Title: | Per-interp Loaded library structures not cleaned up on interp exit. | |||
Type: | Bug | Version: | 8.7 | |
Submitter: | pooryorick | Created on: | 2021-05-15 09:44:07 | |
Subsystem: | - New Builtin Commands | Assigned To: | pooryorick | |
Priority: | 5 Medium | Severity: | Important | |
Status: | Closed | Last Modified: | 2024-11-01 06:58:22 | |
Resolution: | Fixed | Closed By: | jan.nijtmans | |
Closed on: | 2024-11-01 06:58:22 | |||
Description: |
At least through commit [7ffa017f9b76bf5d], The command,
, produces a report indicating indirectly and directly-lost bytes as shown below. The cause is that when an interpreter is cleaned up, the list of loaded libraries is not currently cleaned up, and therefore storage that has been allocated is not deallocated.
| |||
User Comments: |
jan.nijtmans added on 2024-11-01 06:54:37:
Fixed in [3b0e92b198b86975|this]commit. pooryorick added on 2021-05-15 22:30:31: Fixed in [a4de334c5f297a92]. In order to properly clean up, the loaded package, in this case pkgua.c, must be notified when a command is deleted so that it can adjust its books accordingly. A new callback, CommandDeleted, is provided to Tcl_CreateObjCommand, and it does the accounting so that the unload routine doesn't try to delete a command that has already been deleted. Additionally, a new routine, UnloadLibrary, serves both Tcl_UnloadObjCmd and LoadCleanupProc, which takes care of cleanup when an interpreter is deleted. See [723d1eb93779e81b]. UnloadLibrary performs two distinct functions: * remove the library from an interpreter * unload the library from the process It is valid to remove library from an interpreter without unloading the library from the process. Static libraries, for example, can not be unloaded from the process, but unloading them from an interpreter cleans up storage allocated to keep track of libraries loaded into interpreters. In order to completely clean up on interpreter deletion, it is necessary to deallocate this storage, even for a static library. This new implementation also relies on a change made to tclBasic.c/DeleteInterpProc: When associated data is deleted, the corresponding Tcl_InterpDeleteProc is now called before the data is actually deleted instead of after. This allows the Tcl_InterpDeleteProc to use the associated data. See commit [ccfd61a7cf6bce85]. |
