Many functions of tclPathObj are not thread safe (can segfault by changing of FS epoch)
The callstack shows:
Thread 9 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 18320.0x1c0c]
0x50589c0b in tcl85!Tcl_GetStringFromObj () from ./tcl85.dll
(gdb) bt
#0 0x50589c0b in tcl85!Tcl_GetStringFromObj () from ./tcl85.dll
#1 0x505d9e87 in tcl85!TclpMatchInDirectory () from ./tcl85.dll
#2 0x50575db6 in tcl85!Tcl_FSMatchInDirectory () from ./tcl85.dll
...
#35 0x505962fc in tcl85!Tcl_PkgRequireEx () from ./tcl85.dll
After analyzing the code in TclpMatchInDirectory and tclPathObj, the error is obvious - it is occurred by win/tclWinFile.c&ln=981-1007 in ln. 1007 when between ln. 981 and ln. 990 some other thread changing the FS epoch, so the object pathPtr invalidates the internal representation and fileNamePtr disappears.
(Indirectly, this going to the Tcl_FSConvertToPathType which can invalidate the object if check with TclFSEpochOk shows modification of FS epoch, which is system wide so can occur in other thread).
One could surely increment the reference of fileNamePtr in TclpMatchInDirectory temporarily, but there are too many code pieces (inclusive tclPathObj.c itself) with the assumption that if path-object can't shimmer, its internal representation remains the same, what is obviously not the case by this approach considering the system wide epoch.
If this issue cannot be solved using different common approach, the whole code using several path-API functions (in generic/ but also in win/ and unix/) must be reviewed, e. g. extended with incr+decr ref-count for many objects comming from internal representation of path-type objects using Tcl-API or direct assignment.
The crash in TclpMatchInDirectory described here was fixed for [61c01e0edb] by the reference counting added in [0d48bb289c] and [4aae9497e4], in 8.6.17 and 9.0.3. Is there another concrete case left, or can this be closed?