Skip to content
Tcl Source Code Artifact [4a5cb2d40a]
Login

Artifact [4a5cb2d40a]

Artifact 4a5cb2d40aedd9880332837a9a1d3e5bec1cc469:

Ticket change [4a5cb2d40a] - New ticket [2286247fffffffff|2286247fff] <i>Encoding cleanup causes memory errors when exiting</i>. by nobody on 2008-11-14 20:51:42.
D 2008-11-14T20:51:42
J assignee msofer
J cmimetype text/plain
J comment The\scleanup\sfunction\sTcl_FinalizeEncodingSubsystem\s(tclEncoding.c)\scauses\sPurify\sFMR\sand\sFMW\serrors\swhen\sexiting\stcl/tk.\nThe\sproblem\soccurs\swhen\san\sescape-driven\sencoding\sgets\sfreed\safter\sits\sassociated\ssub-encodings\shave\sbeen\sfreed.\sIn\sthat\scase,\sthe\sescape-driven\sencoding\stries\sto\sfree\sits\ssub-encodings,\scausing\smemory\sproblems.\nTo\saddress\sthis\sproblem,\sone\smust\sguarantee\sthat\sthe\sescape-driven\sencodings\sare\sfreed\sbefore\stheir\ssub-encodings.\sThis\scould\sbe\sdone\sby\susing\sa\sstack\s/\slinked\slist\s(instead\sof\sa\shash\stable)\sto\sstore\sthe\sencodings\sin\sthe\sorder\sthey\sare\screated.\sThe\sencodings\swould\shave\sto\sbe\sdeleted\sin\sthe\sreverse\sorder.\sThe\sother\ssolution\s(implemented\sin\sthe\scode\sbelow)\sis\sto\straverse\sthe\shash\stable\smultiple\stimes\sand\sto\sdelete\sthe\sescape-driven\sencodings\sfirst.\sThis\ssolution\sis\smore\sself-contained\sand\sinvolves\sless\schange\sin\sthe\scode\sthan\susing\sa\sdifferent\sdata\sstructure.\n\n\n\nvoid\nTclFinalizeEncodingSubsystem()\n{\n\s\s\s\sTcl_HashSearch\ssearch;\n\s\s\s\sTcl_HashEntry\s*hPtr;\n/*\sSYNOPSYS_START\s*/\n#ifndef\sTCL_ORIG\n\s\s\s\sint\sfound\s=\s1;\n#endif\n/*\sSYNOPSYS_END\s*/\n\s\s\s\sTcl_MutexLock(&encodingMutex);\n\s\s\s\sencodingsInitialized\s\s=\s0;\n\s\s\s\sFreeEncoding(systemEncoding);\n/*\sSYNOPSYS_START\s*/\n#ifndef\sTCL_ORIG\n\s\s\s\s/*\n\s\s\s\s\s*\sFree\sall\sescape-driven\sencodings\sfirst.\sThis\sassumes\sthat\sescape-driven\s\n\s\s\s\s\s*\sencodings\sdo\snot\sreference\sother\sescape-driven\sencodings.\n\s\s\s\s\s*/\n\s\s\s\swhile\s(found)\s{\n\s\s\s\s\s\s\s\sfound\s=\s0;\nhPtr\s=\sTcl_FirstHashEntry(&encodingTable,\s&search);\nwhile\s(hPtr\s!=\sNULL)\s{\n\s\s\s\s\s\s\s\s\s\s\s\sEncoding\s*encodingPtr;\n\s\s\s\sencodingPtr\s=\s(Encoding\s*)\sTcl_GetHashValue(hPtr);\n\s\s\s\sif\s(encodingPtr->freeProc\s==\sEscapeFreeProc)\s{\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s/*\sThis\sis\san\sescape-driven\sencoding.\s*/\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sFreeEncoding((Tcl_Encoding)\sencodingPtr);\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sfound\s=\s1;\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sbreak;\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s/*\sLet's\straverse\sthe\shash\stable\sagain\sfrom\sthe\sstart\sto\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*\sfind\sanother\sescape-driven\sencoding\s(possibly\sthe\ssame\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*\sone\sif\sit\shas\snot\sbeen\sfreed,\sits\sref\scount\snot\shaving\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*\sreached\szero\syet).\sThe\sreason\sfor\sthis\smulti-pass\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*\sapproach\sis\sthat\sfreeing\san\sencoding\smeans\sdeleting\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*\sits\shash\sentry\sand\swe\scannot\sdo\sthat\swhile\straversing\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*\sthe\shash\stable\swith\sTcl_NextHashEntry.\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*/\n\s\s\s\s}\n\s\s\s\shPtr\s=\sTcl_NextHashEntry(&search);\n}\n\s\s\s\s}\n\s\s\s\s/*\sWhat\sremains\sin\sthe\shash\stable\sare\snon-escape-driven\sencodings.\n\s\s\s\s\s*\sLet's\sfree\sthem.\n\s\s\s\s\s*/\n#endif\n/*\sSYNOPSYS_END\s*/\n\n\s\s\s\shPtr\s=\sTcl_FirstHashEntry(&encodingTable,\s&search);\n\s\s\s\swhile\s(hPtr\s!=\sNULL)\s{\n/*\n\s*\sCall\sFreeEncoding\sinstead\sof\sdoing\sit\sdirectly\sto\shandle\srefcounts\n\s*\slike\sescape\sencodings\suse.\s\s[Bug\s#524674]\n\s*\sMake\ssure\sto\scall\sTcl_FirstHashEntry\srepeatedly\sso\sthat\sall\n\s*\sencodings\sare\seventually\scleaned\sup.\n\s*/\nFreeEncoding((Tcl_Encoding)\sTcl_GetHashValue(hPtr));\nhPtr\s=\sTcl_FirstHashEntry(&encodingTable,\s&search);\n\s\s\s\s}\n\s\s\s\sTcl_DeleteHashTable(&encodingTable);\n\s\s\s\sTcl_MutexUnlock(&encodingMutex);\n}
J foundin None
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 10.\sObjects
J title Encoding\scleanup\scauses\smemory\serrors\swhen\sexiting
J type Bug
K 2286247fffffffffffffffffffffffffffffffff
U nobody
Z 53e8b0435ef91cbbc8ebaaadc8f12496