Skip to content
Tcl Source Code Artifact [b12f9cdcee]
Login

Artifact [b12f9cdcee]

Artifact b12f9cdcee99d0247ee19d7da38a1ea999ac0585:

Ticket change [b12f9cdcee] - New ticket [218522ffffffffff|218522ffff] <i>&quot;memory validate on&quot; fails in multithreaded tcl</i>. by nobody on 2000-10-26 01:01:39.
D 2000-10-26T01:01:39
J assignee nobody
J cmimetype text/plain
J comment OriginalBugID:\s880\sBug\nVersion:\s8.1a2\nSubmitDate:\s'1998-11-30'\nLastModified:\s'1998-11-30'\nSeverity:\sSER\nStatus:\sReleased\nSubmitter:\sstanton\nChangedBy:\sstanton\nOS:\sAll\nOSVersion:\sNA\nMachine:\sNA\nFixedDate:\s'1998-11-30'\nFixedInVersion:\s8.1b1\nClosedDate:\s'2000-10-25'\n\n\nI\shave\snow\sverified\sthat\sthe\s"memory\svalidate\son"\sbug\sI\shad\spreviously\nfound\sin\sPtTcl\sstill\sexists\sin\sTcl8.1a2.\s\sBelow\sI\sinclude\sa\stest\swhich\ncauses\sa\scrash,\soutput\sfrom\sdbx\sshowing\swhere\sthe\scrash\shappens,\nmy\sexplanation\sof\sthe\sproblem\sand\sfinally\smy\spatch\sto\sfix\sit.\n\n_________________________________________________________________________\n\nTEST:\sI\srun\stcltest\s(compiled\swith\s-DTCL_MEM_DEBUG),\sturn\son\smemory\n\s\s\s\s\s\svalidation,\sand\sstart\sa\ssecond\sthread\swhich\sperforms\ssome\n\s\s\s\s\s\sdummy\soperations\sto\swhich\swill\scause\smemory\sallocation/\n\s\s\s\s\s\sdeallocation.\s\sThis\scauses\sa\scrash\sas\sif\smemory\swas\scorrupted:\n\n$\s./tcltest\n%\smemory\sinfo\ntotal\smallocs\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s2794\ntotal\sfrees\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s1138\ncurrent\spackets\sallocated\s\s\s\s\s\s\s1656\ncurrent\sbytes\sallocated\s\s\s\s\s\s\s112717\nmaximum\spackets\sallocated\s\s\s\s\s\s\s1672\nmaximum\sbytes\sallocated\s\s\s\s\s\s\s119129\n\n%\smemory\svalidate\son\n%\stestthread\screate\s{while\s1\s{append\sx\sx;\sif\s{[string\slength\s$x]\s>\s1000}\s\s{set\sx\sa;\sputs\s[testthread\sid]}}}\nlow\sguard\sbyte\s0\sis\s0x0\s\s\s\s\s\s\s\s\s\s\nlow\sguard\sbyte\s1\sis\s0x0\s\s\s\s\s\s\s\s\s\s\nlow\sguard\sbyte\s2\sis\s0x0\s\s\s\s\s\s\s\s\s\s\nlow\sguard\sbyte\s3\sis\s0x0\s\s\s\s\s\s\s\s\s\s\nlow\sguard\sbyte\s4\sis\s0x0\s\s\s\s\s\s\s\s\s\s\nlow\sguard\sbyte\s5\sis\s0x0\s\s\s\s\s\s\s\s\s\s\nlow\sguard\sbyte\s6\sis\s0x0\s\s\s\s\s\s\s\s\s\s\nlow\sguard\sbyte\s7\sis\s0x0\s\s\s\s\s\s\s\s\s\s\ntotal\smallocs\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s4882\ntotal\sfrees\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s2496\ncurrent\spackets\sallocated\s\s\s\s\s\s\s2386\ncurrent\sbytes\sallocated\s\s\s\s\s\s\s164465\nmaximum\spackets\sallocated\s\s\s\s\s\s\s2544\nmaximum\sbytes\sallocated\s\s\s\s\s\s\s186687\nlow\sguard\sfailed\sat\s20272b18,\s./../generic/tclStringObj.c\s160\n11\sbytes\sallocated\sat\s(./../generic/tclLiteral.c\s266)\nMemory\svalidation\sfailure\nchild\skilled:\sSIGABRT\n$\s\n\n_________________________________________________________________________\n\nDBX\sSESSION:\n\n$\sdbx\stcltest\score\nType\s'help'\sfor\shelp.\nreading\ssymbolic\sinformation\s...\n[using\smemory\simage\sin\score]\n\nIOT/Abort\strap\sin\spthread_kill\sat\s0xd0168c00\s($t3)\n0xd0168c00\s(pthread_kill+0x130)\s80410014\s\s\s\s\s\s\s\slwz\s\s\sr2,0x14(r1)\n(dbx)\swhere\npthread_kill(??,\s??)\sat\s0xd0168c00\nsignal.raise(??)\sat\s0xd016886c\nabort.abort()\sat\s0xd0d62508\npanic(0x200028d8,\s0x10000000,\s0x0,\s0x10000000,\s0x0,\s0x60000000,\s0x60003d44,\s0x0),\sline\s94\sin\s"panic.c"\nValidateMemory(0x20272af8,\s0x20000938,\s0xa0,\s0x0),\sline\s218\sin\s"tclCkalloc.c"\nTcl_ValidateAllMemory(0x20000938,\s0xa0),\sline\s272\sin\s"tclCkalloc.c"\nTcl_DbCkalloc(0x6,\s0x20000938,\s0xa0),\sline\s350\sin\s"tclCkalloc.c"\nTcl_DbNewStringObj(0x2028de88,\s0x5,\s0x20008d0c,\s0x479),\sline\s160\sin\s"tclStringObj.c"\nTcl_EvalTokens(0x2028f6d8,\s0x202b1c80,\s0x1),\sline\s1145\sin\s"tclParse.c"\nTcl_Eval2(0x2028f6d8,\s0x2028de88,\s0x57,\s0x0),\sline\s1267\sin\s"tclParse.c"\nTcl_Eval(0x2028f6d8,\s0x2028de88),\sline\s1386\sin\s"tclParse.c"\nNewThread(0x2ff21560),\sline\s442\sin\s"tclThreadTest.c"\n_pthread_body(??,\s??)\sat\s0xd015ef4c\n(dbx)\sthread\n\sthread\s\sstate-k\s\s\swchan\sstate-u\s\s\sk-tid\smode\sheld\sscope\sfunction\n\s$t1\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\srunning\s\s\s86693\s\s\s\s\s\s\sno\s\s\ssys\s\s_spin_lock\s\s\s\s\s\s\s\s\s\s\n\s$t2\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\srunning\s\s128679\s\s\s\s\s\s\sno\s\s\ssys\s\sNotifierThreadProc\s\s\n>$t3\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\srunning\s\s275557\s\s\s\s\s\s\sno\s\s\ssys\s\spthread_kill\s\s\s\s\s\s\s\s\n(dbx)\sthread\scurrent\s1\n(dbx)\swhere\n_spin_lock(??)\sat\s0xd015d918\npthread_mutex_lock(??)\sat\s0xd015cbb8\nTclpMutexLock(0x20027f60),\sline\s311\sin\s"tclUnixThrd.c"\nTcl_DbCkfree(0x20272b18,\s0x2000df5c,\s0x264),\sline\s476\sin\s"tclCkalloc.c"\nTclReleaseLiteral(0x20258d68,\s0x2026be18),\sline\s612\sin\s"tclLiteral.c"\nTclCleanupByteCode(0x2028ddd8),\sline\s515\sin\s"tclCompile.c"\nFreeByteCodeInternalRep(0x2026c668),\sline\s418\sin\s"tclCompile.c"\nConvertToStringType(0x2026c668),\sline\s520\sin\s"tclStringObj.c"\nTcl_SetObjLength(0x2026c668,\s0x0),\sline\s279\sin\s"tclStringObj.c"\nTcl_Main(0x1,\s0x2ff22164,\s0x200258d0),\sline\s237\sin\s"tclMain.c"\nmain(argc\s=\s1,\sargv\s=\s0x2ff22164),\sline\s83\sin\s"tclAppInit.c"\n(dbx)\sthread\scurrent\s2\n(dbx)\swhere\nNotifierThreadProc(clientData\s=\s(nil)),\sline\s874\sin\s"tclUnixNotfy.c"\n_pthread_body(??,\s??)\sat\s0xd015ef4c\n(dbx)\s\n_________________________________________________________________________\n\nEXPLANATION:\n\nAccess\sto\sthe\smemory\smanagement\sdata\sstructures\sis\scontrolled\nwith\sa\smutex\scalled\sckallocMutex.\s\sWhen\smemory\svalidation\sis\nturned\son\sand\sa\smemory\sblock\sis\sfreed,\sTcl_DbCkfree\sfirst\nruns\sTcl_ValidateAllMemory\s(which\slocks\sckallocMutex,\schecks\nall\sallocated\sblocks,\sunlocks\sckallocMutex\sand\sreturns),\nthen\sdoes\sValidateMemory(memp,\sfile,\sline,\sTRUE)\nand\sthen\slocks\sckallocMutex\sbefore\scontinuing\sthe\sdeallocation\nprocedure.\n\nThe\sproblem\sis\sthat\swhen\sthe\slast\sparameter\sof\sValidateMemory\n(called\s"nukeguards")\sis\sTRUE,\sit\szeros-out\sthe\sguard\szones\sof\nthe\smemory\sblock\swhich\sis\sabout\sto\sbe\sdeallocated.\s\sIf\sanother\nthread\sis\sconcurrently\sdoing\sValidateAllMemory,\sit\shas\sthe\smutex\nlocked\sand\sthe\sdeallocating\sthread\swaits\sbefore\scompleting\sthe\ndeallocation.\s\sThe\svalidating\sthread\sthen\sfinds\sthat\sthe\sguards\nof\sthe\sblock\swhich\sis\snow\spartly\sdeallocated\shave\schanged\sand\nreports\san\serror.\s\sIn\sthe\sdbx\ssession\sabove\sthread\s3\sis\sthe\n"validating\sthread"\sand\sthread\s1\sis\sthe\s"deallocating\sthread".\n\nMy\sfix\sis\sjust\sto\smove\sthe\slocking\sof\sckallocMutex\sto\sjust\sbefore\nthe\sValidateMemory\scall,\sso\sincluding\sthe\swhole\sdeallocation\nprocess\sinside\sits\sprotection.\s\sAfter\smaking\sthis\sfix\sI\srepeated\nthe\stest\sabove,\sstarting\smultiple\sthreads\sand\sletting\sthem\srun\nfor\ssome\stime\swithout\sa\scrash.\n\n_________________________________________________________________________\n\nPATCH:\n\n***\sgeneric/tclCkalloc.c.orig\s\s\sSat\sFeb\s21\s01:19:22\s1998\n---\sgeneric/tclCkalloc.c\s\s\s\s\s\s\s\sWed\sMar\s\s4\s17:22:05\s1998\n***************\n***\s468,479\s****\n\s\s\s\s\s\sif\s(validate_memory)\n\s\s\s\s\s\s\s\s\s\sTcl_ValidateAllMemory(file,\sline);\n\n\s\s\s\s\s\sValidateMemory(memp,\sfile,\sline,\sTRUE);\n\s\s\s\s\s\sif\s(init_malloced_bodies)\s{\n\s\s\s\s\s\s\s\smemset((VOID\s*)\sptr,\sGUARD_VALUE,\s(size_t)\smemp->length);\n\s\s\s\s\s\s}\n\n-\s\s\s\s\sTclpMutexLock(&ckallocMutex);\n\s\s\s\s\s\stotal_frees++;\n\s\s\s\s\s\scurrent_malloc_packets--;\n\s\s\s\s\s\scurrent_bytes_malloced\s-=\smemp->length;\n---\s468,479\s----\n\s\s\s\s\s\sif\s(validate_memory)\n\s\s\s\s\s\s\s\s\s\sTcl_ValidateAllMemory(file,\sline);\n\n+\s\s\s\s\sTclpMutexLock(&ckallocMutex);\n\s\s\s\s\s\sValidateMemory(memp,\sfile,\sline,\sTRUE);\n\s\s\s\s\s\sif\s(init_malloced_bodies)\s{\n\s\s\s\s\s\s\s\smemset((VOID\s*)\sptr,\sGUARD_VALUE,\s(size_t)\smemp->length);\n\s\s\s\s\s\s}\n\n\s\s\s\s\s\stotal_frees++;\n\s\s\s\s\s\scurrent_malloc_packets--;\n\s\s\s\s\s\scurrent_bytes_malloced\s-=\smemp->length;\n\n\n\n
J foundin obsolete:\s8.1a2
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 49.\sThreading
J title "memory\svalidate\son"\sfails\sin\smultithreaded\stcl
J type Bug
K 218522ffffffffffffffffffffffffffffffffff
U nobody
Z 3707f8d2a2b5ea32076829cbb9e36216