segfault in destruction of static member vtkMathInternal in vtkMath
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I reported first into the mail-list, but I thought was more suitable for a ticket: http://vtk.1045678.n5.nabble.com/vtkMath-segfault-td4917184.html#a5735703
It seems a double destruction or wrong order of destruction of member pointer Gaussian of vtkMathInternal, which is static member of vtkMath http://stackoverflow.com/questions/6850009/c-deleting-static-data suggests a smart pointer for Gaussian, or remove the destructor.
vtk --version = 6.3
//vtkMath.h
static vtkInternal Internal
//vtkMath.cxx
class vtkMathInternal
{
public:
vtkMathInternal();
~vtkMathInternal();
vtkMinimalStandardRandomSequence *Uniform;
vtkBoxMuellerRandomSequence *Gaussian;
std::vector<vtkTypeInt64> MemoizeFactorial;
};
vtkMathInternal::vtkMathInternal()
{
this->Gaussian=vtkBoxMuellerRandomSequence::New();
// This line assumes the current vtkBoxMuellerRandomSequence behavior:
// an initial vtkMinimalStandardRandomSequence is created.
this->Uniform=static_cast<vtkMinimalStandardRandomSequence *>(
this->Gaussian->GetUniformSequence());
this->Uniform->SetSeedOnly(1177); // One authors home address
this->MemoizeFactorial.resize(21, 0);
}
vtkMathInternal::~vtkMathInternal()
{
this->Gaussian->Delete();
}
vtkMathInternal vtkMath::Internal;
Valgrind output:
valgrind -v --leak-check=full ./google-test-with-fixture.run
...
==32109== Invalid free() / delete / delete[] / realloc()
==32109== at 0x4C2A144: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32109== by 0x1D00781D: vtkMathInternal::~vtkMathInternal() (vtkMath.cxx:62)
==32109== Invalid read of size 4
==32109== at 0x1518C4C1: vtkObjectBase::~vtkObjectBase() (in /usr/lib/libvtkCommonCore.so.1)
==32109== by 0x1518C588: vtkObjectBase::~vtkObjectBase() (in /usr/lib/libvtkCommonCore.so.1)
==32109== by 0x1D00781D: vtkMathInternal::~vtkMathInternal() (vtkMath.cxx:62)
==32109== by 0x164D32EE: __cxa_finalize (in /usr/lib/libc-2.22.so)
==32109== by 0x1CEE42A2: ??? (in /home/phc/devtoolset/release/VTK/lib/libvtkCommonCore-6.3.so.1)
==32109== Invalid read of size 4
==32109== at 0x1518C13D: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (in /usr/lib/libvtkCommonCore.so.1)
==32109== by 0x1D00781D: vtkMathInternal::~vtkMathInternal() (vtkMath.cxx:62)
==32109== at 0x1518C1F0: vtkObjectBase::Delete() (in /usr/lib/libvtkCommonCore.so.1)
==32109== by 0x1D00781D: vtkMathInternal::~vtkMathInternal() (vtkMath.cxx:62)
==32109== Invalid read of size 8
==32109== at 0x1518C090: vtkObjectBase::UnRegister(vtkObjectBase*) (in /usr/lib/libvtkCommonCore.so.1)
==32109== by 0x1D00781D: vtkMathInternal::~vtkMathInternal() (vtkMath.cxx:62)