<i>memory leak: SetFsPathFromAny, assisted by the global literal table, causes a Tcl_Obj to reference itself</i>.
by
.
D 2023-03-26T10:30:33.937
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment [https://core.tcl-lang.org/tcl/file?udc=1&ln=2359&ci=c02747a663bc158a&name=generic%2FtclPathObj.c|SetFsPathFromAny]\r\nduplicates\sa\sTcl_Obj\sand\sthen\sstores\sa\spointer\sto\sthe\snew\sobject\sin\sa\r\nfsPathPtr,\swhich\sit\sthen\ssets\sas\sthe\sinternal\srepresentation\sof\sanother\r\nTcl_Obj,\spathPtr.\s\sBecause\sno\scare\sis\staken\sto\sensure\sthat\sthe\sinternal\r\nrepresentation\sof\sthe\snewly-duplicated\sTcl_Obj\scontains\sno\sreference-counted\r\ncopy\sof\spathPtr,\sit's\spossible\sfor\sa\ssituation\sto\sarise\swhere\spathPtr\scontains\r\na\spointer\sto\sitself,\sand\sthat\sits\sreference\scount\stherefore\snever\sdrops\sto\s0,\r\nwhich\sis\sa\smemory\sleak.\r\n\r\nIn\stest\sTcl_Main-2.1\ssuch\sa\ssituation\sdoes\sin\sfact\soccur:\s\s"result"\sis\sa\r\nliteral\svalue\sthat,\sby\sthe\stime\sSetFsPathFromAny\sreceives\sit,\shas\salready\sbeen\r\nentered\sinto\sthe\sliteralTable\sof\sthe\sinterpreter,\sand\shas\salso\sreceived\san\r\ninternal\srepresentation\sof\stype\s"localVarNameType",\spossibly\sdue\sto\sits\r\nappearance\sin\sprocedures\swithin\smsgcat.tcl.\s\sWhen\spathPtr\sis\sduplicated,\r\nDupLocalVarName()\r\n[https://core.tcl-lang.org/tcl/file?udc=1&ln=5809&ci=c02747a663bc158a&name=generic%2FtclVar.c|makes\r\npathPtr\sthe\sinternal\srepresentation\sof\sthe\sduplicated\sobject],\stransPtr.\s\sThen\r\ntransPtr\sis\sstored\sin\sfsPathPtr,\swhich\sbecomtes\sthe\sinternal\srepresentation\sof\r\npathPtr.\s\sValgrind\sreports\sstill-reachable\sblocks\sdue\sto\sthis\ssituation,\sbut\r\nonly\swhen\sall\sother\stests\sare\sdeleted\sfrom\sthe\ssource\sfile.\r\n\r\nAlthough\sthis\sissue\scan\sbe\sfixed\sby\smodifying\sSetFsPathFromAny,\sit\sis\syet\r\nanother\sexample\sof\show\ssharing\sa\ssingle\sTcl_Obj\sbetween\sidentical\sliteral\r\nvalues\scauses\strouble.\s\sFirst,\sit\screates\sa\ssituation\swhere\sthere\sis\sonly\sone\r\ninternal\srepresentation\seven\sthough\sthe\sidentical\sliteral\svalues\smay\shave\r\ndifferent\scontexts\sand\sinterpretations.\s\sSecond,\sit\smakes\serrors\slike\sthis\sone,\r\nwhich\scan\sgo\sundiscovered\sfor\syears,\smore\slikely.
J is_private 0
J login pooryorick
J priority 5\sMedium
J private_contact 2b2275eab1118e1fab0016cf1c5702893c6af86c
J resolution None
J severity Critical
J status Open
J submitter pooryorick
J subsystem 36.\sPathname\sManagement
J title memory\sleak:\s\sSetFsPathFromAny,\sassisted\sby\sthe\sglobal\sliteral\stable,\scauses\sa\sTcl_Obj\sto\sreference\sitself
J type Bug
K 6d4e9d1af5bf5b7dc8c359c2c169974c0b963066
U pooryorick
Z 1c2dd1972488b5810109101008ad7591