D 2020-05-22T12:12:47.825 J assignee nobody J closer nobody J cmimetype text/x-fossil-wiki J comment Here\sis\sa\sdouble\sfree\sbug\sthat\ssomeone\soriginally\sreported\sfor\sPerl/Tk\s([https://rt.cpan.org/Public/Bug/Display.html?id=102648]),\sbut\swhich\sI\sreplicated\sin\sTcl/Tk\susing\sboth\sthe\soriginal\sPerl/Tk\sexample\sthrough\sTcl::pTk,\sas\swell\sas\sa\snearly\sequivalent\sTcl\ssyntax\sexample:\r\n\r\n
\r\npackage\srequire\sTk\r\n\r\nset\sen_text\s{Type\s'A'\shere}\r\npack\s[entry\s.e\s\\\r\n\s\s\s\s-textvariable\sen_text\s\\\r\n\s\s\s\s-validate\skey\s\\\r\n\s\s\s\s-validatecommand\s{\r\n\s\s\s\s\s\s\s\sif\s{"%S"\seq\s{A}}\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\sset\sen_text\s%P\r\n\s\s\s\s\s\s\s\s\s\s\s\s.e\sconfigure\s-validate\skey\r\n\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\sreturn\s1\r\n\s\s\s\s}\r\n]\r\n
\r\n\r\nPressing\s'A'\scauses\sthe\sdouble\sfree\sin\sthis\sexample.\sWhen\sthe\skey\sis\spressed,\sInsertChars()\sstores\sthe\sexisting\sentryPtr->string\sin\sthe\svariable\sstring.\sIt\sthen\sdoes\sthe\sEntryValidate()\s→\sEntryValidateChange()\sto\sevaluate\sthe\svalidatecommand\sscript.\sWhen\sthe\stextvariable\sis\sset\sin\sthe\sscript,\sthis\sinvokes\sEntryTextVarProc()\s→\sEntrySetValue()\swhich\sfrees\sthe\sexisting\sentryPtr->string.\sAfter\svalidation\sfinishes,\sEntrySet()\sthen\stries\sto\sfree\sthe\salready-freed\saddress\sin\sstring.\r\n\r\nIt's\snot\sobvious\sto\sme\swhat\sshould\sbe\sdone\sabout\sthis\sissue.\sShould\sthis\sat\sleast\snot\slead\sto\sa\scrash/corruption,\sor\sis\sit\sbelieved\sthat\sthe\sdocumentation\salready\sfirmly\swarned\sagainst\smixing\s-textvariable\sand\s-validatecommand\ssuch\sthat\sthis\sissue\sis\sexpected\sbehavior?\sAt\sa\sminimum,\sit\spreferably\scrashes\srather\sthan\ssilently\scorrupts—i.e.\spanic\sif\sstring\s!=\sentryPtr->string\sjust\sbefore\sckfree((char\s*)string).\r\n\r\nI\sam\snot\saware\sof\sthis\sissue\saffecting\sTtk\sentry\swidgets. J foundin 8.6.10 J is_private 0 J login chrstphrchvz J priority 5\sMedium J resolution None J severity Important J status Open J submitter chrstphrchvz J subsystem 07.\s[entry] J title Entry:\sdouble\sfree\swhen\stextvariable\sset\sin\svalidatecommand\sscript J type Bug K 40e4bf61988580b8ffaecd1d57a7087ba76b54d4 U chrstphrchvz Z 5d0851794d81d9d3be5bfa4abf8e56dc