Skip to content
Tcl Source Code Artifact [cf6467decc]
Login

Artifact [cf6467decc]

Artifact cf6467decce51d1718b994e36d86413474e2a5d6:

Ticket change [cf6467decc] - New ticket [756791ffffffffff|756791ffff] <i>Tcl incorrectly uses ckfree() when freeProc == free()</i>. by landonf on 2003-06-18 19:17:52.
D 2003-06-18T19:17:52
J assignee hobbs
J cmimetype text/plain
J comment Tcl\sincorrectly\suses\sckfree()\son\spointers\ssupplied\swith\sa\s\nfreeProc\sof\sfree()\n\nFix\sattached,\sexplanation\sbelow.\n\nPrototype\sfor\sTcl_SetResult:\nTcl_SetResult(interp,\sstring,\sfreeProc)\n\nTcl_SetResult\sallows\sone\sto\sspecify\sany\scustom\sfree\sfunction\s\nthat\smatches\sthe\sTcl_FreeProc\sprototype,\sor\sone\sof\s\nTCL_VOLATILE,\sTCL_STATIC,\sor\sTCL_DYNAMIC.\n\nIf\sone\sspecifies\sTCL_DYNAMIC,\sit\sis\sassumed\sthat\sthe\sstring\s\npointer\sis\sowned\sby\sthe\sTcl\sallocator,\sand\sckfree()\sis\sused\sto\s\nfree\sthe\sallocated\smemory.\n\nHowever,\sif\sfree()\sis\sspecified,\sckfree()\sis\sALSO\sused\sto\sfree\s\nthe\sallocated\smemory.\sThis\sis\sincorrect,\sas\sckfree()\scan\snot\s\nbe\sused\son\smemory\sallocated\sby\smalloc.\n\n\s\s\s\s\s\s\s\sif\s((iPtr->freeProc\s==\sTCL_DYNAMIC)\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\nfree))\s{\nckfree(iPtr->result);\n}\n\nWhen\slooking\sthrough\sthe\scode,\sI\sfound\sthat\sthis\serror\swas\s\npropagated\sin\snumerous\sother\slocations.\sAttached\sis\sa\sfix.\sIn\s\nall\scases,\sthe\sabove\sif\sconditional\shas\sbeen\schanged\sto\s\nremove\sthe\stest\sfor\siPtr->freeProc\s==\s(Tcl_FreeProc\s*)\s\nfree.\sIn\sexample:\nif\s(iPtr->freeProc\s==\sTCL_DYNAMIC)\s{\n...\n}\n\nDetailed\sproblem\sinformation\sfollows:\n\nTcl_DStringGetResult(interp,\sdsPtr):\nIf\siPtr->freeProc\sis\seither\sTCL_DYNAMIC\sor\sfree,\sdsPtr-\n>string\sis\sset\sto\siPtr->result.\sLater,\swhen\sTcl_DStringFree()\s\nis\scalled,\sckfree()\swill\sbe\scalled\son\sdsPtr->string.\n\nTcl_Release(clientData):\nIf\sTcl_EventuallyFree\shas\sbeen\scalled\son\sthe\spointer\spassed\s\nto\sTcl_Release,\srefPtr->mustFree\swill\sbe\sset,\sand\srefPtr-\n>freeProc\swill\sbe\sset\sto\sthe\sfree\sfunction\sgiven\sto\s\nTcl_EventuallyFree.\sIf\srefPtr->freeProc\sis\seither\s\nTCL_DYNAMIC\sor\sfree,\sckfree(clientData)\swill\sbe\scalled.\n\nTcl_EventuallyFree(clientData,\sfreeProc):\nIf\sthere\sis\sno\sreference\sin\sthe\srefArray\sfor\sthe\sclientData\s\npointer,\sclientData\sis\simmediately\sfreed\susing\sthe\ssupplied\s\nfreeProc,\sunless\sfreeProc\s==\sfree()\sor\sTCL_DYNAMIC,\sand\s\nthen,\sckfree(clientData)\sis\scalled.\n\nTcl_DiscardResult(statePtr)\nIf\sTcl_SetResult\swas\scalled\swith\sa\sfreeProc\sof\sfree,\s\nTcl_SaveResult(interp,\sstatePtr)\swill\sset\sstatePtr->freeProc\s\nto\siPtr->freeProc,\sand\sstatePtr->result\sto\siPtr->result.\sWhen\s\nTcl_DiscardResult\sis\scalled\son\sthis\sstatePtr,\sif\sstatePtr-\n>freeProc\sis\sTCL_DYNAMIC\sor\sfree(),\sckfree()\sis\scalled\son\s\nstatPtr->result.\n\nTcl_SetResult(interp,\sstring,\sfreeProc)\nIf\sthe\sold\sinterp->freeProc\sis\sTCL_DYNAMIC\sor\sfree(),\sckfree\s\nis\scalled.\n\nTcl_SetObjResult(interp,\sobjPtr)\nIf\sinterp->result\s&&\sinterp->freeProc\sare\snot\sNULL,\sand\s\ninterp->freeProc\sis\seither\sTCL_DYNAMIC\sor\sfree(),\sckfree()\s\nis\scalled.\n\nTcl_GetObjResult(interp):\nIf\sinterp->result\s&&\sinterp->freeProc\sare\snot\sNULL,\sand\s\ninterp->freeProc\sis\seither\sTCL_DYNAMIC\sor\sfree(),\sckfree()\s\nis\scalled.\n\nTcl_FreeResult(interp):\nIf\sinterp->freeProc\sis\snot\sNULL,\sand\sinterp->freeProc\sis\s\neither\sTCL_DYNAMIC\sor\sfree(),\sckfree()\sis\scalled.\n
J foundin None
J priority 5\sMedium
J resolution None
J status Open
J submitter landonf
J subsystem 41.\sMemory\sAllocation
J title Tcl\sincorrectly\suses\sckfree()\swhen\sfreeProc\s==\sfree()
J type Bug
K 756791ffffffffffffffffffffffffffffffffff
U landonf
Z 41619e6cc40539ab26f363e523258513