<i>[patch]Tcl incorrectly uses ckfree() when freeProc == free()</i> status still Closed with 8 other changes
by
.
D 2023-10-11T12:58:56.621
J assignee aku
J closedate 2460229.04093311
J closer chrstphrchvz
J comment Tcl\sincorrectly\suses\sckfree()\son\spointers\ssupplied\swith\sa\s\r\nfreeProc\sof\sfree()\r\n\r\nFix\sattached,\sexplanation\sbelow.\r\n\r\nPrototype\sfor\sTcl_SetResult:\r\nTcl_SetResult(interp,\sstring,\sfreeProc)\r\n\r\nTcl_SetResult\sallows\sone\sto\sspecify\sany\scustom\sfree\sfunction\s\r\nthat\smatches\sthe\sTcl_FreeProc\sprototype,\sor\sone\sof\s\r\nTCL_VOLATILE,\sTCL_STATIC,\sor\sTCL_DYNAMIC.\r\n\r\nIf\sone\sspecifies\sTCL_DYNAMIC,\sit\sis\sassumed\sthat\sthe\sstring\s\r\npointer\sis\sowned\sby\sthe\sTcl\sallocator,\sand\sckfree()\sis\sused\sto\s\r\nfree\sthe\sallocated\smemory.\r\n\r\nHowever,\sif\sfree()\sis\sspecified,\sckfree()\sis\sALSO\sused\sto\sfree\s\r\nthe\sallocated\smemory.\sThis\sis\sincorrect,\sas\sckfree()\scan\snot\s\r\nbe\sused\son\smemory\sallocated\sby\smalloc.\r\n\r\n\s\s\s\s\s\s\s\sif\s((iPtr->freeProc\s==\sTCL_DYNAMIC)\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s||\s(iPtr->freeProc\s==\s(Tcl_FreeProc\s*)\s\r\nfree))\s{\r\nckfree(iPtr->result);\r\n}\r\n\r\nWhen\slooking\sthrough\sthe\scode,\sI\sfound\sthat\sthis\serror\swas\s\r\npropagated\sin\snumerous\sother\slocations.\sAttached\sis\sa\sfix.\sIn\s\r\nall\scases,\sthe\sabove\sif\sconditional\shas\sbeen\schanged\sto\s\r\nremove\sthe\stest\sfor\siPtr->freeProc\s==\s(Tcl_FreeProc\s*)\s\r\nfree.\sIn\sexample:\r\nif\s(iPtr->freeProc\s==\sTCL_DYNAMIC)\s{\r\n...\r\n}\r\n\r\nDetailed\sproblem\sinformation\sfollows:\r\n\r\nTcl_DStringGetResult(interp,\sdsPtr):\r\nIf\siPtr->freeProc\sis\seither\sTCL_DYNAMIC\sor\sfree,\sdsPtr-\r\n>string\sis\sset\sto\siPtr->result.\sLater,\swhen\sTcl_DStringFree()\s\r\nis\scalled,\sckfree()\swill\sbe\scalled\son\sdsPtr->string.\r\n\r\nTcl_Release(clientData):\r\nIf\sTcl_EventuallyFree\shas\sbeen\scalled\son\sthe\spointer\spassed\s\r\nto\sTcl_Release,\srefPtr->mustFree\swill\sbe\sset,\sand\srefPtr-\r\n>freeProc\swill\sbe\sset\sto\sthe\sfree\sfunction\sgiven\sto\s\r\nTcl_EventuallyFree.\sIf\srefPtr->freeProc\sis\seither\s\r\nTCL_DYNAMIC\sor\sfree,\sckfree(clientData)\swill\sbe\scalled.\r\n\r\nTcl_EventuallyFree(clientData,\sfreeProc):\r\nIf\sthere\sis\sno\sreference\sin\sthe\srefArray\sfor\sthe\sclientData\s\r\npointer,\sclientData\sis\simmediately\sfreed\susing\sthe\ssupplied\s\r\nfreeProc,\sunless\sfreeProc\s==\sfree()\sor\sTCL_DYNAMIC,\sand\s\r\nthen,\sckfree(clientData)\sis\scalled.\r\n\r\nTcl_DiscardResult(statePtr)\r\nIf\sTcl_SetResult\swas\scalled\swith\sa\sfreeProc\sof\sfree,\s\r\nTcl_SaveResult(interp,\sstatePtr)\swill\sset\sstatePtr->freeProc\s\r\nto\siPtr->freeProc,\sand\sstatePtr->result\sto\siPtr->result.\sWhen\s\r\nTcl_DiscardResult\sis\scalled\son\sthis\sstatePtr,\sif\sstatePtr-\r\n>freeProc\sis\sTCL_DYNAMIC\sor\sfree(),\sckfree()\sis\scalled\son\s\r\nstatPtr->result.\r\n\r\nTcl_SetResult(interp,\sstring,\sfreeProc)\r\nIf\sthe\sold\sinterp->freeProc\sis\sTCL_DYNAMIC\sor\sfree(),\sckfree\s\r\nis\scalled.\r\n\r\nTcl_SetObjResult(interp,\sobjPtr)\r\nIf\sinterp->result\s&&\sinterp->freeProc\sare\snot\sNULL,\sand\s\r\ninterp->freeProc\sis\seither\sTCL_DYNAMIC\sor\sfree(),\sckfree()\s\r\nis\scalled.\r\n\r\nTcl_GetObjResult(interp):\r\nIf\sinterp->result\s&&\sinterp->freeProc\sare\snot\sNULL,\sand\s\r\ninterp->freeProc\sis\seither\sTCL_DYNAMIC\sor\sfree(),\sckfree()\s\r\nis\scalled.\r\n\r\nTcl_FreeResult(interp):\r\nIf\sinterp->freeProc\sis\snot\sNULL,\sand\sinterp->freeProc\sis\s\r\neither\sTCL_DYNAMIC\sor\sfree(),\sckfree()\sis\scalled.
J icomment There\sis\sstill\san\sinstance\sof\sthis\sissue\sin\sTk:\s[https://core.tcl-lang.org/tk/info/9675dd5916ba]
J login chrstphrchvz
J mimetype text/x-fossil-wiki
J severity Minor
K 756791ffffffffffffffffffffffffffffffffff
U chrstphrchvz
Z c20d90c287ceeb137ea918d5ea46c135