Index: generic/threadCmd.c ================================================================== --- generic/threadCmd.c +++ generic/threadCmd.c @@ -1630,17 +1630,20 @@ { ThreadClbkData *clbkPtr = (ThreadClbkData*)clientData; const char *var = (const char *)clbkPtr->clientData; Tcl_Obj *valObj; ThreadEventResult *resultPtr = &clbkPtr->result; + int rc = TCL_OK; /* * Get the result of the posted command. * We will use it to fill-in the result variable. */ valObj = Tcl_NewStringObj(resultPtr->result, -1); + Tcl_IncrRefCount(valObj); + if (resultPtr->result != threadEmptyResult) { ckfree(resultPtr->result); } /* @@ -1647,11 +1650,12 @@ * Set the result variable */ if (Tcl_SetVar2Ex(interp, var, NULL, valObj, TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) == NULL) { - return TCL_ERROR; + rc = TCL_ERROR; + goto cleanup; } /* * In case of error, trigger the bgerror mechansim */ @@ -1669,11 +1673,13 @@ } Tcl_SetObjResult(interp, valObj); Tcl_BackgroundError(interp); } - return TCL_OK; +cleanup: + Tcl_DecrRefCount(valObj); + return rc; } /* *---------------------------------------------------------------------- *