From b85082ab57e74309a18d2acbc82e907c28aa97e4 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 13 Nov 2024 15:47:21 +0000 Subject: [PATCH] fixes segfault [d4ba38d00d06ebba]: only main interpreter used as default thread interpreter (stored in its TSD) --- generic/threadCmd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/generic/threadCmd.c b/generic/threadCmd.c index ce10e43..6e25103 100644 --- a/generic/threadCmd.c +++ b/generic/threadCmd.c @@ -583,8 +583,17 @@ Init( ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); if (tsdPtr->interp == NULL) { + Tcl_Interp *tmpInterp, *mainInterp = interp; memset(tsdPtr, 0, sizeof(ThreadSpecificData)); - tsdPtr->interp = interp; + /* + * Retrieve main interpreter of the thread, only + * main interpreter used as default thread-interpreter, + * so no childs here, see bug [d4ba38d00d06ebba] + */ + while (mainInterp && (tmpInterp = Tcl_GetMaster(mainInterp))) { + mainInterp = tmpInterp; + } + tsdPtr->interp = mainInterp; ListUpdate(tsdPtr); Tcl_CreateThreadExitHandler(ThreadExitProc, threadEmptyResult);