Tcl Source Code

Hex Artifact Content
Login

Artifact b39e14ba53d51672a6b8eb0391b99f3826f74106:

Ticket change [b39e14ba53] - 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 2017-07-17 16:59:39.
0000: 44 20 32 30 31 37 2d 30 37 2d 31 37 54 31 36 3a  D 2017-07-17T16:
0010: 35 39 3a 33 39 2e 38 37 39 0a 4a 20 69 63 6f 6d  59:39.879.J icom
0020: 6d 65 6e 74 20 57 65 6c 6c 2c 5c 73 74 68 69 73  ment Well,\sthis
0030: 5c 73 73 65 65 6d 73 5c 73 74 6f 5c 73 68 61 76  \sseems\sto\shav
0040: 65 5c 73 72 65 70 65 72 63 75 73 73 69 6f 6e 73  e\srepercussions
0050: 5c 73 2d 5c 73 74 6f 64 61 79 5c 73 49 5c 73 77  \s-\stoday\sI\sw
0060: 6f 75 6c 64 5c 73 63 68 65 63 6b 5c 73 6d 79 5c  ould\scheck\smy\
0070: 73 69 64 65 61 5c 73 77 69 74 68 5c 73 6e 65 77  sidea\swith\snew
0080: 5c 73 66 6c 61 67 5c 73 3c 63 6f 64 65 3e 54 43  \sflag\s<code>TC
0090: 4c 5f 4f 57 4e 5f 4f 42 4a 52 45 46 3c 2f 63 6f  L_OWN_OBJREF</co
00a0: 64 65 3e 5c 73 61 6e 64 5c 73 68 61 76 65 5c 73  de>\sand\shave\s
00b0: 76 65 72 69 66 69 65 64 5c 73 61 74 5c 73 77 68  verified\sat\swh
00c0: 69 63 68 5c 73 70 6c 61 63 65 73 5c 73 65 76 65  ich\splaces\seve
00d0: 72 79 77 68 65 72 65 5c 73 69 6e 5c 73 74 63 6c  rywhere\sin\stcl
00e0: 5c 73 28 61 6e 64 5c 73 73 6f 6d 65 5c 73 6d 6f  \s(and\ssome\smo
00f0: 64 75 6c 65 73 5c 73 6c 69 6b 65 5c 73 74 68 72  dules\slike\sthr
0100: 65 61 64 2c 5c 73 65 74 63 29 5c 73 69 74 5c 73  ead,\setc)\sit\s
0110: 6d 61 79 5c 73 62 65 5c 73 6e 65 65 64 65 64 2e  may\sbe\sneeded.
0120: 5c 72 5c 6e 54 68 65 72 65 62 79 5c 73 49 5c 73  \r\nThereby\sI\s
0130: 66 6f 75 6e 64 5c 73 6d 61 6e 79 5c 73 70 6c 61  found\smany\spla
0140: 63 65 73 2c 5c 73 77 68 65 72 65 5c 73 69 74 27  ces,\swhere\sit'
0150: 73 5c 73 63 75 72 72 65 6e 74 6c 79 5c 73 77 72  s\scurrently\swr
0160: 6f 6e 67 5c 73 28 65 2e 5c 73 67 2e 5c 73 75 73  ong\s(e.\sg.\sus
0170: 61 67 65 5c 73 6f 66 5c 73 72 65 6c 65 61 73 65  age\sof\srelease
0180: 64 5c 73 6f 62 6a 65 63 74 2c 5c 73 77 72 6f 6e  d\sobject,\swron
0190: 67 5c 73 66 72 65 65 5c 73 6f 72 5c 73 65 76 65  g\sfree\sor\seve
01a0: 6e 5c 73 6c 65 61 6b 73 29 2e 3c 62 72 2f 3e 5c  n\sleaks).<br/>\
01b0: 72 5c 6e 54 6f 6f 5c 73 6d 61 6e 79 5c 73 74 6f  r\nToo\smany\sto
01c0: 5c 73 6c 69 73 74 5c 73 61 6c 6c 5c 73 74 68 69  \slist\sall\sthi
01d0: 73 5c 73 68 65 72 65 2e 2e 2e 3c 62 72 2f 3e 5c  s\shere...<br/>\
01e0: 72 5c 6e 4a 75 73 74 5c 73 61 73 5c 73 61 6e 5c  r\nJust\sas\san\
01f0: 73 65 78 61 6d 70 6c 65 2c 5c 73 73 65 65 5c 73  sexample,\ssee\s
0200: 3c 61 5c 73 68 72 65 66 3d 22 68 74 74 70 73 3a  <a\shref="https:
0210: 2f 2f 63 6f 72 65 2e 74 63 6c 2e 74 6b 2f 74 63  //core.tcl.tk/tc
0220: 6c 2f 61 72 74 69 66 61 63 74 2f 33 39 36 63 31  l/artifact/396c1
0230: 34 35 64 64 64 65 64 63 37 64 30 3f 6c 6e 3d 32  45dddedc7d0?ln=2
0240: 37 35 30 22 3e 54 63 6c 5f 4f 62 6a 53 65 74 56  750">Tcl_ObjSetV
0250: 61 72 32 28 2e 2e 2e 2c 5c 73 6d 61 74 63 68 56  ar2(...,\smatchV
0260: 61 72 4f 62 6a 2c 5c 73 4e 55 4c 4c 2c 5c 73 65  arObj,\sNULL,\se
0270: 6d 70 74 79 4f 62 6a 2c 5c 73 2e 2e 2e 29 3c 2f  mptyObj,\s...)</
0280: 61 3e 5c 73 74 68 61 74 5c 73 77 69 6c 6c 5c 73  a>\sthat\swill\s
0290: 75 73 65 5c 73 61 6c 72 65 61 64 79 5c 73 72 65  use\salready\sre
02a0: 6c 65 61 73 65 64 5c 73 6f 62 6a 65 63 74 5c 73  leased\sobject\s
02b0: 3c 63 6f 64 65 3e 65 6d 70 74 79 4f 62 6a 3c 2f  <code>emptyObj</
02c0: 63 6f 64 65 3e 5c 73 69 66 5c 73 31 30 5c 73 6c  code>\sif\s10\sl
02d0: 69 6e 65 73 5c 73 3c 61 5c 73 68 72 65 66 3d 22  ines\s<a\shref="
02e0: 68 74 74 70 73 3a 2f 2f 63 6f 72 65 2e 74 63 6c  https://core.tcl
02f0: 2e 74 6b 2f 74 63 6c 2f 61 72 74 69 66 61 63 74  .tk/tcl/artifact
0300: 2f 33 39 36 63 31 34 35 64 64 64 65 64 63 37 64  /396c145dddedc7d
0310: 30 3f 6c 6e 3d 32 37 34 30 22 3e 61 62 6f 76 65  0?ln=2740">above
0320: 3c 2f 61 3e 5c 73 74 68 65 5c 73 73 61 6d 65 5c  </a>\sthe\ssame\
0330: 73 6f 62 6a 65 63 74 5c 73 3c 63 6f 64 65 3e 65  sobject\s<code>e
0340: 6d 70 74 79 4f 62 6a 3c 2f 63 6f 64 65 3e 5c 73  mptyObj</code>\s
0350: 77 69 6c 6c 5c 73 62 65 5c 73 72 65 6c 65 61 73  will\sbe\sreleas
0360: 65 64 5c 73 69 6e 5c 73 74 72 61 63 65 5c 73 62  ed\sin\strace\sb
0370: 79 5c 73 3c 63 6f 64 65 3e 54 63 6c 5f 4f 62 6a  y\s<code>Tcl_Obj
0380: 53 65 74 56 61 72 32 28 2e 2e 2e 2c 5c 73 69 6e  SetVar2(...,\sin
0390: 64 65 78 56 61 72 4f 62 6a 2c 5c 73 4e 55 4c 4c  dexVarObj,\sNULL
03a0: 2c 5c 73 65 6d 70 74 79 4f 62 6a 2c 5c 73 2e 2e  ,\semptyObj,\s..
03b0: 2e 29 5c 73 3c 2f 63 6f 64 65 3e 2e 5c 72 5c 6e  .)\s</code>.\r\n
03c0: 4e 6f 74 65 5c 73 74 68 61 74 5c 73 69 6e 5c 73  Note\sthat\sin\s
03d0: 63 75 72 72 65 6e 74 5c 73 76 65 72 73 69 6f 6e  current\sversion
03e0: 73 5c 73 74 68 69 73 5c 73 64 6f 65 73 5c 73 6e  s\sthis\sdoes\sn
03f0: 6f 74 5c 73 68 61 76 65 5c 73 3c 63 6f 64 65 3e  ot\shave\s<code>
0400: 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e 74  Tcl_DecrRefCount
0410: 28 65 6d 70 74 79 4f 62 6a 29 3c 2f 63 6f 64 65  (emptyObj)</code
0420: 3e 5c 73 69 6e 5c 73 65 72 72 6f 72 5c 73 63 61  >\sin\serror\sca
0430: 73 65 73 5c 73 28 73 69 6e 63 65 5c 73 61 75 74  ses\s(since\saut
0440: 6f 2d 72 65 6c 65 61 73 65 5c 73 69 6e 5c 73 5b  o-release\sin\s[
0450: 35 31 30 36 36 33 61 39 39 65 33 61 30 39 36 62  510663a99e3a096b
0460: 62 37 62 61 62 37 33 31 34 65 62 35 39 66 63 38  b7bab7314eb59fc8
0470: 30 35 33 33 35 33 31 38 5d 29 2c 5c 73 62 75 74  05335318]),\sbut
0480: 5c 73 69 74 5c 73 64 6f 65 73 5c 73 6e 6f 5c 73  \sit\sdoes\sno\s
0490: 6d 61 74 74 65 72 5c 73 62 65 63 61 75 73 65 5c  matter\sbecause\
04a0: 73 74 68 69 73 5c 73 63 61 6e 5c 73 62 65 5c 73  sthis\scan\sbe\s
04b0: 72 65 6c 65 61 73 65 64 5c 73 69 6e 5c 73 74 72  released\sin\str
04c0: 61 63 65 5c 73 62 79 5c 73 73 65 74 2e 5c 72 5c  ace\sby\sset.\r\
04d0: 6e 5c 72 5c 6e 49 5c 73 77 6f 75 6c 64 5c 73 6c  n\r\nI\swould\sl
04e0: 69 6b 65 5c 73 74 6f 5c 73 66 69 78 5c 73 61 6c  ike\sto\sfix\sal
04f0: 6c 5c 73 73 75 63 68 5c 73 65 72 72 6f 72 73 5c  l\ssuch\serrors\
0500: 73 28 61 6e 64 5c 73 73 69 6d 69 6c 61 72 29 5c  s(and\ssimilar)\
0510: 73 66 6f 72 5c 73 38 2e 35 74 68 2c 5c 73 38 2e  sfor\s8.5th,\s8.
0520: 36 74 68 5c 73 61 6e 64 5c 73 74 72 75 6e 6b 5c  6th\sand\strunk\
0530: 73 62 72 61 6e 63 68 65 73 5c 73 28 74 6f 67 65  sbranches\s(toge
0540: 74 68 65 72 5c 73 77 69 74 68 5c 73 69 6e 74 72  ther\swith\sintr
0550: 6f 64 75 63 69 6e 67 5c 73 6f 66 5c 73 61 6c 72  oducing\sof\salr
0560: 65 61 64 79 5c 73 73 75 67 67 65 73 74 65 64 5c  eady\ssuggested\
0570: 73 6e 65 77 5c 73 66 6c 61 67 5c 73 54 43 4c 5f  snew\sflag\sTCL_
0580: 4f 57 4e 5f 4f 42 4a 52 45 46 5c 73 6f 72 5c 73  OWN_OBJREF\sor\s
0590: 75 73 69 6e 67 5c 73 73 6f 6d 65 5c 73 6f 74 68  using\ssome\soth
05a0: 65 72 5c 73 73 6f 6c 75 74 69 6f 6e 5c 73 6c 69  er\ssolution\sli
05b0: 6b 65 5c 73 6e 65 77 5c 73 69 6e 74 65 72 6e 61  ke\snew\sinterna
05c0: 6c 5c 73 66 75 6e 63 74 69 6f 6e 5c 73 3c 63 6f  l\sfunction\s<co
05d0: 64 65 3e 54 63 6c 4f 62 6a 4f 77 6e 41 6e 64 53  de>TclObjOwnAndS
05e0: 65 74 56 61 72 3c 2f 63 6f 64 65 3e 29 2c 5c 73  etVar</code>),\s
05f0: 62 75 74 5c 73 66 69 72 73 74 6c 79 5c 73 49 5c  but\sfirstly\sI\
0600: 73 77 6f 75 6c 64 5c 73 6c 69 6b 65 5c 73 74 6f  swould\slike\sto
0610: 5c 73 6b 6e 6f 77 5c 73 77 68 61 74 5c 73 54 43  \sknow\swhat\sTC
0620: 54 5c 73 74 68 69 6e 6b 73 5c 73 61 62 6f 75 74  T\sthinks\sabout
0630: 5c 73 28 6e 65 77 5c 73 66 6c 61 67 3f 2c 5c 73  \s(new\sflag?,\s
0640: 6e 65 77 5c 73 66 75 6e 63 74 69 6f 6e 3f 2c 5c  new\sfunction?,\
0650: 73 73 6f 6d 65 74 68 69 6e 67 5c 73 6f 74 68 65  ssomething\sothe
0660: 72 3f 29 2e 5c 72 5c 6e 49 4d 48 4f 5c 73 62 75  r?).\r\nIMHO\sbu
0670: 74 5c 73 28 76 65 72 79 2d 76 65 72 79 5c 73 63  t\s(very-very\sc
0680: 6f 6e 74 72 6f 76 65 72 73 69 61 6c 29 5c 73 61  ontroversial)\sa
0690: 75 74 6f 2d 72 65 6c 65 61 73 65 5c 73 6d 61 64  uto-release\smad
06a0: 65 5c 73 69 6e 5c 73 5b 35 31 30 36 36 33 61 39  e\sin\s[510663a9
06b0: 39 65 33 61 30 39 36 62 62 37 62 61 62 37 33 31  9e3a096bb7bab731
06c0: 34 65 62 35 39 66 63 38 30 35 33 33 35 33 31 38  4eb59fc805335318
06d0: 5d 5c 73 69 73 5c 73 6e 6f 74 5c 73 72 65 61 6c  ]\sis\snot\sreal
06e0: 6c 79 5c 73 61 5c 73 73 6f 6c 75 74 69 6f 6e 5c  ly\sa\ssolution\
06f0: 73 61 6e 64 5c 73 73 68 6f 75 6c 64 5c 73 62 65  sand\sshould\sbe
0700: 5c 73 72 65 77 72 69 74 74 65 6e 2e 5c 72 5c 6e  \srewritten.\r\n
0710: 5c 72 5c 6e 50 6c 65 61 73 65 5c 73 6e 6f 74 65  \r\nPlease\snote
0720: 5c 73 61 6c 73 6f 2c 5c 73 74 68 61 74 5c 73 74  \salso,\sthat\st
0730: 68 69 73 5c 73 62 65 68 61 76 69 6f 72 5c 73 69  his\sbehavior\si
0740: 73 5c 73 75 6e 64 6f 63 75 6d 65 6e 74 65 64 2c  s\sundocumented,
0750: 5c 73 73 6f 5c 73 6d 61 6e 79 5c 73 70 65 6f 70  \sso\smany\speop
0760: 6c 65 5c 73 6d 61 6b 65 5c 73 73 74 69 6c 6c 3a  le\smake\sstill:
0770: 5c 72 5c 6e 3c 63 6f 64 65 3e 3c 70 72 65 3e 5c  \r\n<code><pre>\
0780: 72 5c 6e 54 63 6c 5f 4f 62 6a 5c 73 2a 6e 65 77  r\nTcl_Obj\s*new
0790: 4f 62 6a 5c 73 3d 5c 73 53 6f 6d 65 74 68 69 6e  Obj\s=\sSomethin
07a0: 67 52 65 74 75 72 6e 73 4e 65 77 4f 62 6a 4f 66  gReturnsNewObjOf
07b0: 54 79 70 65 58 28 2e 2e 2e 29 3b 5c 72 5c 6e 69  TypeX(...);\r\ni
07c0: 66 5c 73 28 54 63 6c 5f 4f 62 6a 53 65 74 56 61  f\s(Tcl_ObjSetVa
07d0: 72 32 28 2e 2e 2e 2c 5c 73 76 61 72 4f 62 6a 2c  r2(...,\svarObj,
07e0: 5c 73 4e 55 4c 4c 2c 5c 73 6e 65 77 4f 62 6a 2c  \sNULL,\snewObj,
07f0: 5c 73 2e 2e 2e 29 5c 73 3d 3d 5c 73 4e 55 4c 4c  \s...)\s==\sNULL
0800: 29 5c 73 7b 5c 72 5c 6e 5c 73 5c 73 54 63 6c 5f  )\s{\r\n\s\sTcl_
0810: 44 65 63 72 52 65 66 43 6f 75 6e 74 28 6e 65 77  DecrRefCount(new
0820: 4f 62 6a 29 3b 5c 72 5c 6e 5c 73 5c 73 72 65 74  Obj);\r\n\s\sret
0830: 75 72 6e 5c 73 54 43 4c 5f 45 52 52 4f 52 3b 5c  urn\sTCL_ERROR;\
0840: 72 5c 6e 7d 5c 72 5c 6e 3c 2f 70 72 65 3e 3c 2f  r\n}\r\n</pre></
0850: 63 6f 64 65 3e 5c 72 5c 6e 57 68 61 74 5c 73 69  code>\r\nWhat\si
0860: 73 5c 73 63 75 72 72 65 6e 74 6c 79 5c 73 77 72  s\scurrently\swr
0870: 6f 6e 67 5c 73 28 62 65 63 61 75 73 65 5c 73 73  ong\s(because\ss
0880: 69 6e 63 65 5c 73 5b 35 31 30 36 36 33 61 39 39  ince\s[510663a99
0890: 65 33 61 30 39 36 62 62 37 62 61 62 37 33 31 34  e3a096bb7bab7314
08a0: 65 62 35 39 66 63 38 30 35 33 33 35 33 31 38 5d  eb59fc805335318]
08b0: 5c 73 69 74 5c 73 69 73 5c 73 64 6f 75 62 6c 65  \sit\sis\sdouble
08c0: 5c 73 64 65 63 72 65 61 73 65 64 2c 5c 73 61 6e  \sdecreased,\san
08d0: 64 5c 73 63 61 6e 5c 73 63 61 75 73 65 5c 73 73  d\scan\scause\ss
08e0: 65 67 66 61 75 6c 74 29 2e 0a 4a 20 6c 6f 67 69  egfault)..J logi
08f0: 6e 20 73 65 62 72 65 73 0a 4a 20 6d 69 6d 65 74  n sebres.J mimet
0900: 79 70 65 20 74 65 78 74 2f 78 2d 66 6f 73 73 69  ype text/x-fossi
0910: 6c 2d 77 69 6b 69 0a 4b 20 35 37 38 31 35 35 64  l-wiki.K 578155d
0920: 35 61 31 39 62 33 34 38 64 63 31 61 39 66 65 39  5a19b348dc1a9fe9
0930: 36 63 63 32 63 30 36 37 61 35 39 33 32 36 61 38  6cc2c067a59326a8
0940: 39 0a 55 20 73 65 62 72 65 73 0a 5a 20 32 36 36  9.U sebres.Z 266
0950: 33 34 30 37 38 64 36 30 32 61 37 64 39 31 61 61  34078d602a7d91aa
0960: 64 38 34 61 62 65 34 38 65 65 63 33 63 0a        d84abe48eec3c.