Calling smtk::graph::Resource::arcs() with non-const return type results Seg
Calling smtk::graph::Resource::arcs()
with non-const return type results in an attempted double free in smtk::common::TypeMapBase<>::~TypeMapBase()
. If you use const auto& myArcs = graph->arcs()
you can get around this for now.
Example code:
{
MyGraphResource::Ptr graph = MyGraphResource::create();
// Blah blah add arcs and nodes to graph. Won't crash with no arcs, because ~TypeMapBase
// does no deletes on an empty unordered_map.
// Now we go to a nested scope.
{
auto myArcs = graph->arcs();
// The destructor of the smtk::common::TypeMap runs and deletes all of the arcs in
// template <typename KeyType> inline TypeMapBase<KeyType>::~TypeMapBase()
}
// 1. |graph| reference count goes to zero.
// 2. smtk::graph::Resource::~Resource().
// 3. smtk::common::TypeMapBase<>::~TypeMapBase() tries to free the Arcs again.
}
Example of Seg:
#0 0x0000000000000051 in ?? ()
#1 0x00007fffedac65c4 in smtk::common::TypeMapBase<smtk::common::UUID>::~TypeMapBase (this=0x8e06b0,
__in_chrg=<optimized out>) at /opt/cmb-6.3.0/include/smtk/3.3.0/smtk/common/TypeMap.h:252
#2 0x00007fffedac4d52 in smtk::common::TypeMap<smtk::common::UUID>::~TypeMap (this=0x8e06b0,
__in_chrg=<optimized out>) at /opt/cmb-6.3.0/include/smtk/3.3.0/smtk/common/TypeMap.h:283
#3 0x00007fffedb7e7ec in smtk::graph::Resource<smtk::session::mysession::MeshAssemblyGraphTraits>::~Resource
(this=0x8e03f0, __in_chrg=<optimized out>)
at /opt/cmb-6.3.0/include/smtk/3.3.0/smtk/graph/Resource.h:45
#4 0x00007fffedb7e860 in smtk::resource::DerivedFrom<smtk::session::mysession::MyResource, smtk::graph::Resource<smtk::session::mysession::MyResourceGraphTraits> >::~DerivedFrom (this=0x8e03f0,
__in_chrg=<optimized out>) at /opt/cmb-6.3.0/include/smtk/3.3.0/smtk/resource/DerivedFrom.h:32
#5 0x00007fffedb81c4a in smtk::session::mysession::MyResource::~MyResource (
this=0x8e03f0, __in_chrg=<optimized out>)
at /opt/mysession/src/my_resource/MyResource.h:39
#6 0x00007fffedb81c7a in smtk::session::mysession::MyResource::~MyResource (
this=0x8e03f0, __in_chrg=<optimized out>)
at /opt/mysession/src/my_resource/MyResource.h:39
#7 0x000000000048db3e in std::_Sp_counted_ptr<smtk::session::mysession::MyResource*, (__gnu_cxx::_Lock_policy)2>::_M_dispose (this=0x8dfe60) at /usr/include/c++/5/bits/shared_ptr_base.h:374
#8 0x0000000000470cee in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x8dfe60)
at /usr/include/c++/5/bits/shared_ptr_base.h:150
#9 0x00000000004701c1 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (
this=0x7fffffffd718, __in_chrg=<optimized out>) at /usr/include/c++/5/bits/shared_ptr_base.h:659
#10 0x000000000046fcbc in std::__shared_ptr<smtk::session::mysession::MyResource, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x7fffffffd710, __in_chrg=<optimized out>)
at /usr/include/c++/5/bits/shared_ptr_base.h:925
#11 0x000000000046fcd8 in std::shared_ptr<smtk::session::mysession::MyResource>::~shared_ptr (
this=0x7fffffffd710, __in_chrg=<optimized out>) at /usr/include/c++/5/bits/shared_ptr.h:93
#12 0x000000000046c412 in JsonMyResourceResourceTest_Serializes_Test::TestBody (this=0x8df500)
at /opt/mysession/tests/cxx/unittesting/UnitTestJsonMyResource.cxx:22
#13 0x00000000004b7647 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ()
#14 0x00000000004b19d3 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ()
#15 0x0000000000495a50 in testing::Test::Run() ()
#16 0x000000000049635a in testing::TestInfo::Run() ()
#17 0x00000000004969c5 in testing::TestCase::Run() ()
#18 0x000000000049d90a in testing::internal::UnitTestImpl::RunAllTests() ()
#19 0x00000000004b858d in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ()
#20 0x00000000004b27dd in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::Un---Type <return> to continue, or q <return> to quit---
itTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ()
#21 0x000000000049c500 in testing::UnitTest::Run() ()
#22 0x00000000004c636f in RUN_ALL_TESTS() ()
#23 0x00000000004c6309 in main ()
FYI @bob.obara @dcthomp