<i>SIGSEGV on shutdown with TclOO, coroutines, namespaces, and -DPURIFY</i> status still Open with 4 other changes
by
.
D 2024-12-03T23:04:58.872
J icomment I\sinvestigated\sfurther.\s\s`-DPURIFY`\sis\snot\sitself\sthe\sproblem,\srather\sit\scauses\sthe\sprogram\sto\simmediately\scrash\supon\suse-after-free.\s\sOmitting\s`-DPURIFY`\sonly\ssucceeds\sin\smasking\sthe\sproblem.\s\sIt\smight\sbe\spossible\sto\scrash\seven\swithout\s`-DPURIFY`\sby\ssomehow\scausing\sallocation\sbetween\sthe\sfree\sand\sthe\suse-after-free.\r\n\r\nCurious\sif\sthe\sproblem\scould\sbe\striggered\sby\schild\sinterpreters\swithout\susing\s`-DPURIFY`\s(the\sanswer\sis\sno),\sI\samended\sthe\stest\sscript,\swhile\ssticking\swith\scommit\s[b688a485b2](https://core.tcl-lang.org/tcl/info/b688a485b253869b):\r\n\r\n```\r\ninterp\screate\schild\r\nchild\seval\s{\r\n\s\s\s\soo::class\screate\sclass\r\n\s\s\s\soo::define\sclass\smethod\syield\s{}\s{yield}\r\n\s\s\s\snamespace\seval\sns\s{coroutine\scoro\s[class\snew]\syield}\r\n}\r\ninterp\sdelete\schild\r\n```\r\n\r\nThe\s`oPtr`\spassed\sto\s`TclOOObjectName`\scomes\sfrom\s`mPtr->declaringClassPtr->thisPtr`.\s\sGiven\sthis\sexact\stest\sscript\sand\sTcl\sversion,\sthis\sfield\sis\sset\sby\sthe\s21st\scrossing\sof\stclOO.c:1686\s(`TclOOAllocClass`).\s\sWhen\susing\s`-DPURIFY`,\sit\slater\sgets\strashed\sby\s`Tcl_Free`\scalled\sby\sthe\s2nd\scrossing\sof\stclOO.c:1384\s(`TclOODecrRefCount`).\s\sWhen\snot\susing\s`-DPURIFY`,\sthe\sclass\sstruct\spointer\sis\sstill\spassed\sto\s`Tcl_Free`,\sbut\ssaid\sfunction\sdoes\snot\swipe\sthe\sclass\sstruct,\sthus\sits\sfields\scan\sbe\sread\swithout\scomplaint.\s\sAt\sleast\suntil\sthe\snext\sallocation\shappens,\sI\swould\simagine.\r\n\r\nThe\strouble\sarises\sbecause\sthe\sclass\sis\sdeallocated\sbefore\sthe\scoroutine\swhich\syielded\sinside\sa\sclass\smethod,\sbut\sthe\ssuspended\scoroutine\scleanup\sthen\swants\sto\sinclude\sthe\sclass\sname\sin\sthe\serror\sreport.\s\sI'm\snot\squite\ssure\swhere\sthe\serror\sreport\sis\sexpected\sto\sgo,\sbut\sit's\sbeing\smade\sbecause\s`TEBCresume`\swas\sinstructed\sto\sresume\sexecution\sof\sa\srewound\scoroutine.\r\n\r\nTo\ssee\sthe\sproblem,\sget\sthe\sabove-mentioned\scrash\sscript\sand\sTcl\scommit\stree,\sbuild\swith\s`--enable-symbols`\sand\seither\swith\sor\swithout\s`-DPURIFY`,\sthen\sdo:\r\n\r\n```\r\ncd\r\ngdb\s--args\stcl/install/bin/tclsh9.0\scrash.tcl\r\nstart\r\ntb\stclOO.c:1686\r\nignore\s2\s20\r\ntb\stclOO.c:1384\r\nignore\s3\s1\r\nc\r\np\sclsPtr\r\nc\r\np\soPtr->classPtr\r\nn\r\nrwatch\s-l\soPtr->classPtr->thisPtr\r\nc\r\n```\r\n\r\nRunning\sthe\sabove\ssequence\sshows\sthat\s`oPtr->classPtr->thisPtr`\sgets\sread\sby\s`MethodErrorHandler`\sdespite\shaving\scalled\s`TclFree(oPtr->classPtr)`.\r\n\r\nRepeating,\sthis\stime\sshowing\sselected\sgdb\soutput:\r\n\r\n```\r\n$\scd\r\n$\sgdb\s--args\stcl/install/bin/tclsh9.0\scrash.tcl\r\n(gdb)\sstart\r\nTemporary\sbreakpoint\s1\sat\s0x401185:\sfile\s/root/tcl/unix/tclAppInit.c,\sline\s91.\r\n(gdb)\stb\stclOO.c:1686\r\nTemporary\sbreakpoint\s2\sat\s0x7ffff7f326d3:\sfile\s/root/tcl/generic/tclOO.c,\sline\s1686.\r\n(gdb)\signore\s2\s20\r\nWill\signore\snext\s20\scrossings\sof\sbreakpoint\s2.\r\n(gdb)\stb\stclOO.c:1384\r\nTemporary\sbreakpoint\s3\sat\s0x7ffff7f31fe1:\sfile\s/root/tcl/generic/tclOO.c,\sline\s1384.\r\n(gdb)\signore\s3\s1\r\nWill\signore\snext\scrossing\sof\sbreakpoint\s3.\r\n(gdb)\sc\r\nContinuing.\r\nTemporary\sbreakpoint\s2,\sTclOOAllocClass\s(interp=0x4ac250,\suseThisObj=0x5880a0)\sat\s/root/tcl/generic/tclOO.c:1686\r\n1686\s\s\s\s\s\s\s\sclsPtr->thisPtr\s=\suseThisObj;\r\n(gdb)\sp\sclsPtr\r\n$1\s=\s(Class\s*)\s0x587ca0\r\n(gdb)\sp\suseThisObj\r\n$2\s=\s(Object\s*)\s0x5880a0\r\n(gdb)\sc\r\nContinuing.\r\nTemporary\sbreakpoint\s3,\sTclOODecrRefCount\s(oPtr=0x5880a0)\sat\s/root/tcl/generic/tclOO.c:1384\r\n1384\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sTcl_Free(oPtr->classPtr);\r\n(gdb)\sp\soPtr->classPtr\r\n$3\s=\s(Class\s*)\s0x587ca0\r\n(gdb)\sn\r\n(gdb)\srwatch\s-l\soPtr->classPtr->thisPtr\r\nHardware\sread\swatchpoint\s4:\s-location\soPtr->classPtr->thisPtr\r\n(gdb)\sc\r\nContinuing.\r\nHardware\sread\swatchpoint\s4:\s-location\soPtr->classPtr->thisPtr\r\nValue\s=\s(Object\s*)\s0x5880a0\r\n0x00007ffff7f49da4\sin\sMethodErrorHandler\s(interp=0x4ac250,\sdummy1213=0x54b0a0)\sat\s/root/tcl/generic/tclOOMethod.c:1231\r\n1231\s\s\s\s\s\s\s\s\s\s\s\sdeclarerPtr\s=\smPtr->declaringClassPtr->thisPtr;\r\n```\r\n\r\nFor\sthe\srecord,\sI\sdid\sthis\stest\susing\sSlackware64\s15.0\splus\sgcc-14.2.0-x86_64-2.txz,\sbinutils-2.43.1-x86_64-1.txz,\sand\sglibc-2.40-x86_64-5.txz\sfrom\sSlackware64-current.
J login andy
J mimetype text/x-markdown
J username andy
K 0b809cd3fc8b6e5e19cd8a9a91357e425472cd69
U andy
Z 4236371a32214582b3be0077efb05b6f