Skip to content
Tcl Source Code Artifact [e1880f0a41]
Login

Artifact [e1880f0a41]

Artifact e1880f0a4105031fa935906ae9e596d8c5fcd4b98858236d6a2c71e2cfbeefe5:

Ticket change [e1880f0a41] - Ticket [578155d5a19b348d|578155d5a1] <i>Very rare bug (segfault) if set variable (with error case) using self-releasable object as new value</i> status still Open with 3 other changes by sebres on 2018-01-11 16:46:03.
D 2018-01-11T16:46:03.527
J icomment >\sIf\syou\sfind\scode\slike\sthis\sanywhere:\r\n>\sif\s(Tcl_ObjSetVar2(interp,\svarObj,\sNULL,\snewObj,\s0)\s==\sNULL)\s{Tcl_DecrRefCount(newObj);}\r\n>\s...\r\n>\sBut\sthat's\sthe\sonly\sbug\sI\ssee.\r\n\r\nWell,\sthis\swould\sbe\sso,\sif\sthe\sTcl_ObjSetVar2\swill\sget\s"ownership"\sfor\sthe\sobject\salways,\salso\sin\sthe\serror\scase.\r\n\r\nBut,\sthe\sproblem\sis\svery,\svery\sserious,\sDon.\r\n\r\nCurrently,\sTcl_ObjSetVar\s"owns"\sobject\sonly\sin\ssuccess-case,\sAND\sin\serror\scase,\sBUT\sthen\sonly\sif\srefCount\sis\s0!\sAFTER\sthe\s"failed"\sattempt\sof\sassignment,\sDon!\r\n\r\nSo\sI\ssee\sat\sleast\s2\sissues\shere:\r\n\s\s1)\sThe\sfunction\schecks\sthe\srefCount\sonly\sAFTER\strying\sof\sset\sthe\svariable\s(which\scan\schange\sthe\srefCount\sof\sthe\sobject\sby\scalling\sof\sthe\straces,\setc).\sMuch\sworse\sit\slooks\sjust\slike\sundefined\sbehavior.\r\n\s\s2)\sFor\sthe\sdeveloper\susing\sTcl_ObjSetVar,\sit\sis\svery\sbad\sup\sto\simpossible\sto\sact\splausible\sin\serror\scase,\sbecause\she\sdon't\sknow\swhen\she\sshould\sdecrease\srefCount\sin\serror\scase\sor\snot,\sespecially\sbecause\sthe\sobject\scan\sbe\sreleased\swithin\sTcl_ObjSetVar,\sand\sthen\sthe\sdeveloper\shas\snormally\sno\schance\sto\scheck\sthe\srefCount\s(resp.\sthe\svitality\sof\sthe\sobject\shereafter\sis\sunknown\sin\serror\scase).\s\r\n\r\nThus\seither\she\sdo\sthis\snevertheless\sand\scan\sget\ssegfault,\sor\she\sproduces\sintentionally\sa\smemory\sleak\s(quasi\saccepts\sthe\srisk\sof\spossible\sleak).\r\n\r\nAdditionally\sit\sis\svery\sconfusing\sbehavior\sfor\sthe\sfunction\sfrom\spublic\sAPI\sin\smy\sunderstanding...\sAlso\sif\sthis\swill\sbe\s"correctly"\sdocumented.\r\n\r\nIn\smy\sopinion\sit\sis\swrong\sso\sit\sis\simplemented.
J login sebres
J mimetype text/plain
K 578155d5a19b348dc1a9fe96cc2c067a59326a89
U sebres
Z c791b76dd004120b352e9981d9016d75