From 1d4f551278f3f36f063591ecc1a6bd2e7964b14f Mon Sep 17 00:00:00 2001 From: pooryorick Date: Wed, 12 Aug 2020 13:28:08 +0000 Subject: Fix for [3422267ed6b7], segmentation fault with imported alias. --- generic/tclNamesp.c | 7 ++++++- generic/tclProc.c | 7 +++++++ tests/interp.test | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index 26dca62..fea23aa 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -959,7 +959,7 @@ Tcl_DeleteNamespace( /* * If the namespace has associated ensemble commands, delete them first. * This leaves the actual contents of the namespace alone (unless they are - * linked ensemble commands, of course). Note that this code is actually + * linked ensemble commands, of course). This code is * reentrant so command delete traces won't purturb things badly. */ @@ -1770,7 +1770,9 @@ DoImport( TclInvokeImportedCmd, InvokeImportedNRCmd, dataPtr, DeleteImportedCmd); dataPtr->realCmdPtr = cmdPtr; + cmdPtr->refCount++; dataPtr->selfPtr = (Command *) importedCmd; + dataPtr->selfPtr->refCount++; dataPtr->selfPtr->compileProc = cmdPtr->compileProc; Tcl_DStringFree(&ds); @@ -1781,6 +1783,7 @@ DoImport( refPtr = (ImportRef *)ckalloc(sizeof(ImportRef)); refPtr->importedCmdPtr = (Command *) importedCmd; + refPtr->importedCmdPtr->refCount++; refPtr->nextPtr = cmdPtr->importRefPtr; cmdPtr->importRefPtr = refPtr; } else { @@ -2076,7 +2079,9 @@ DeleteImportedCmd( } else { prevPtr->nextPtr = refPtr->nextPtr; } + TclCleanupCommandMacro(refPtr->importedCmdPtr); ckfree(refPtr); + TclCleanupCommandMacro(selfPtr) ckfree(dataPtr); return; } diff --git a/generic/tclProc.c b/generic/tclProc.c index 0d67c37..150d036 100644 --- a/generic/tclProc.c +++ b/generic/tclProc.c @@ -215,6 +215,7 @@ Tcl_ProcObjCmd( */ procPtr->cmdPtr = (Command *) cmd; + procPtr->cmdPtr->refCount++; /* * TIP #280: Remember the line the procedure body is starting on. In a @@ -2154,6 +2155,12 @@ TclProcCleanupProc( ckfree(localPtr); localPtr = nextPtr; } + /* + * TclOOMethod.c:clOOMakeProcMethod sets cmdPtr to NULL + */ + if (procPtr->cmdPtr) { + TclCleanupCommandMacro(procPtr->cmdPtr); + } ckfree(procPtr); /* diff --git a/tests/interp.test b/tests/interp.test index 599ac08..35f3390 100644 --- a/tests/interp.test +++ b/tests/interp.test @@ -3664,6 +3664,13 @@ test interp-38.8 {interp debug basic setup} -body { } -returnCodes { error } -result {wrong # args: should be "interp debug path ?-frame ?bool??"} + +test interp-39.0 { + no segmentation fault when a command is deleted +} -body { +} -cleanup { +} -result 1 + # cleanup unset -nocomplain hidden_cmds -- cgit v0.12