Index: generic/nsf.c =================================================================== diff -u -N -r6be629efed541f89533ca7f798c698102f827f6e -r59b4e8cdea04398a07a8ac5a87550a411cf4c095 --- generic/nsf.c (.../nsf.c) (revision 6be629efed541f89533ca7f798c698102f827f6e) +++ generic/nsf.c (.../nsf.c) (revision 59b4e8cdea04398a07a8ac5a87550a411cf4c095) @@ -25254,25 +25254,6 @@ } #endif -#if defined(NSF_MEM_COUNT) - /* The Tcl history list (which internally stores commands and scripts in the - array ::tcl::history) can retain Tcl_Obj references beyond the scope of - our shutdown procedures (::nsf::finalize, ExitHandler). Therefore, on - MEM_COUNT_RELEASE(), we might see unbalanced refcounts which are false - positives. Therefore, we aim at clearing the history list at this point. - - See also Tcl bug report 1ae12987cb. - */ - result = Tcl_Eval(interp, "::history clear"); - - if (unlikely(result != TCL_OK)) { - NsfLog(interp, NSF_LOG_WARN, "Clearing the Tcl history list failed! " - "Memcounts could be reported as unbalanced on MEM_COUNT_RELEASE(). " - "Error: %s\n", - ObjStr(Tcl_GetObjResult(interp))); - } -#endif - /*fprintf(stderr, "+++ call tcl-defined exit handler (%x)\n", PTR2INT(pthread_self()));*/ /* @@ -31850,6 +31831,24 @@ CallStackPopAll(interp); +#if defined(NSF_MEM_COUNT) + /* The Tcl history list (which internally stores commands and scripts in the + array ::tcl::history) can retain Tcl_Obj references beyond the scope of + our shutdown procedures (::nsf::finalize, ExitHandler). Therefore, on + MEM_COUNT_RELEASE(), we might see unbalanced refcounts which are false + positives. Therefore, we aim at clearing the history list at this point. + + See also Tcl bug report 1ae12987cb. + */ + + if (unlikely(Tcl_Eval(interp, "::history clear") != TCL_OK)) { + NsfLog(interp, NSF_LOG_WARN, "Clearing the Tcl history list failed! " + "Memcounts could be reported as unbalanced on MEM_COUNT_RELEASE(). " + "Error: %s\n", + ObjStr(Tcl_GetObjResult(interp))); + } +#endif + if (rst->exitHandlerDestroyRound == NSF_EXITHANDLER_OFF) { NsfFinalizeCmd(interp, 0); }