|
2018-04-23
| ||
| 13:54 | • Closed ticket [8ecaee5d83]: array for memory corruption plus 6 other chang... artifact: b8ad1cd7c3 user: dgp | |
| 13:01 | • Ticket [8ecaee5d83]: 3 changes artifact: 2c0cd4d338 user: bll | |
| 12:27 | • Ticket [8ecaee5d83]: 3 changes artifact: 505c59f544 user: bll | |
| 11:39 | • Ticket [8ecaee5d83]: 3 changes artifact: dbbb18fcbc user: dgp | |
| 10:51 | • Ticket [8ecaee5d83]: 3 changes artifact: 8cf68b864c user: bll | |
| 03:27 | • New ticket [8ecaee5d83]. artifact: ee4c2e82bc user: dgp | |
[array for] memory corruption
Closed / Fixed8ecaee5d83a8d8694bd0585066d6d6f71c28ce73Created 9 years agoUpdated 9 years ago
Descriptionplain2018-04-23 03:27:38
In a --enable-symbols=mem build of Tcl, both tests var-23.10 and var-23.11 segfault. This is because the unset operations in the loop bodies cause searchPtr to be freed, yet ArrayForLoopCallback() operates on the fields of searchPtr right away with nothing to check the memory is still allocated. Array searches are still not yet founded on a proper design.
bllplain2018-04-23 10:51:35
The varPtr assignment needs to be moved below the result check.
Index: generic/tclVar.c
==================================================================
--- generic/tclVar.c
+++ generic/tclVar.c
@@ -3128,12 +3128,10 @@
/*
* Process the result from the previous execution of the script body.
*/
done = TCL_ERROR;
- varPtr = TclObjLookupVarEx(interp, searchPtr->arrayNameObj, NULL, /*flags*/ 0,
- /*msg*/ 0, /*createPart1*/ 0, /*createPart2*/ 0, &arrayPtr);
if (result == TCL_CONTINUE) {
result = TCL_OK;
} else if (result != TCL_OK) {
if (result == TCL_BREAK) {
@@ -3144,10 +3142,13 @@
"\n (\"array for\" body line %d)",
Tcl_GetErrorLine(interp)));
}
goto arrayfordone;
}
+
+ varPtr = TclObjLookupVarEx(interp, searchPtr->arrayNameObj, NULL, /*flags*/ 0,
+ /*msg*/ 0, /*createPart1*/ 0, /*createPart2*/ 0, &arrayPtr);
/*
* Get the next mapping from the array.
*/
dgpplain2018-04-23 11:39:44
Thanks. That does look like an improvement, but it doesn't solve the problem.
Program received signal SIGSEGV, Segmentation fault.
0x0000000000589a7b in TclObjLookupVarEx (interp=0x83a678,
part1Ptr=0x6161616161616161, part2Ptr=0x0, flags=0, msg=0x0,
createPart1=0, createPart2=0, arrayPtrPtr=0x7fffffffd020)
at /home/dgp/fossil/tcl8.7/generic/tclVar.c:551
551 const Tcl_ObjType *typePtr = part1Ptr->typePtr;
Missing separate debuginfos, use: debuginfo-install glibc-2.17-196.el7_4.2.x86_64 zlib-1.2.7-17.el7.x86_64
(gdb) bt
#0 0x0000000000589a7b in TclObjLookupVarEx (interp=0x83a678,
part1Ptr=0x6161616161616161, part2Ptr=0x0, flags=0, msg=0x0,
createPart1=0, createPart2=0, arrayPtrPtr=0x7fffffffd020)
at /home/dgp/fossil/tcl8.7/generic/tclVar.c:551
#1 0x000000000058d0ef in ArrayForLoopCallback (data=0xe1ade0,
interp=0x83a678, result=0) at /home/dgp/fossil/tcl8.7/generic/tclVar.c:3147
#2 0x0000000000430d24 in TclNRRunCallbacks (interp=0x83a678, result=0,
rootPtr=0x0) at /home/dgp/fossil/tcl8.7/generic/tclBasic.c:4494
When the problem arises, ArrayForLoopCallback() is entered with
result == TCL_OK. It is this pass through the routine that is
supposed to notice the array change and report the error.
bllplain2018-04-23 12:27:58
Ugh. I suppose an additional hash entry must be made in the varSearches hash table in order to save the array name.
bllplain2018-04-23 13:01:55
Ok, having the arrayNameObj in the ArraySearch structure would never work. Fortunately, there was still a slot available in the NRE callback to pass another variable. I also moved the duplicated code to populate the search structure into a new routine. http://core.tcl.tk/tcl/info/70852914044fa64a
dgpplain2018-04-23 13:54:10
That appears to have solve that issue. Thanks for the work repairing the rotten foundations! (Not your fault that they were rotten to begin with). Will keep hammering on [array for] as I can.
Log in (anonymous is fine) to add a comment.