diff options
author | pooryorick <com.digitalsmarties@pooryorick.com> | 2017-12-20 18:26:40 (GMT) |
---|---|---|
committer | pooryorick <com.digitalsmarties@pooryorick.com> | 2017-12-20 18:26:40 (GMT) |
commit | c1f84789ba402e590faed95132cf3f621c9bd0bf (patch) | |
tree | 618681b9d7437448af23fb2db5e41c006896a5c6 | |
parent | e10cd2e0a52b97a25e6e05658f8f96b2f53bf45c (diff) | |
download | tcl-c1f84789ba402e590faed95132cf3f621c9bd0bf.zip tcl-c1f84789ba402e590faed95132cf3f621c9bd0bf.tar.gz tcl-c1f84789ba402e590faed95132cf3f621c9bd0bf.tar.bz2 |
Fix for issue [ba1419303b4c]: Delete a namespace for an ensemble having a deletion
trace deletes its namespace: segmentation fault.
-rw-r--r-- | generic/tclNamesp.c | 17 | ||||
-rw-r--r-- | tests/namespace.test | 13 |
2 files changed, 20 insertions, 10 deletions
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index a8d351f..542d648 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -916,6 +916,11 @@ Tcl_DeleteNamespace( Command *cmdPtr; /* + * Ensure that this namespace doesn't get deallocated in the meantime. + */ + nsPtr->refCount++; + + /* * Give anyone interested - notably TclOO - a chance to use this namespace * normally despite the fact that the namespace is going to go. Allows the * calling of destructors. Will only be called once (unless re-established @@ -1047,16 +1052,8 @@ Tcl_DeleteNamespace( #endif Tcl_DeleteHashTable(&nsPtr->cmdTable); - /* - * If the reference count is 0, then discard the namespace. - * Otherwise, mark it as "dead" so that it can't be used. - */ - - if (nsPtr->refCount == 0) { - NamespaceFree(nsPtr); - } else { - nsPtr->flags |= NS_DEAD; - } + nsPtr ->flags |= NS_DEAD; + TclNsDecrRefCount(nsPtr); } else { /* * Restore the ::errorInfo and ::errorCode traces. diff --git a/tests/namespace.test b/tests/namespace.test index ff8cd7d..f2d7061 100644 --- a/tests/namespace.test +++ b/tests/namespace.test @@ -196,6 +196,19 @@ test namespace-7.7 {Bug 1655305} -setup { interp delete slave } -result {} +test namespace-7.8 {Bug ba1419303b4c} -setup { + namespace eval ns1 { + namespace ensemble create + } + + trace add command ns1 delete { + namespace delete ns1 + } +} -body { + # No segmentation fault given --enable-symbols=mem. + namespace delete ns1 +} -result {} + test namespace-8.1 {TclTeardownNamespace, delete global namespace} { catch {interp delete test_interp} interp create test_interp |