MantisBT - VTK
View Issue Details
0015909VTK(No Category)public2015-12-30 04:312016-08-12 09:55
Pablo Hernandez-Cerdan 
Kitware Robot 
normalminorhave not tried
closedmoved 
6.3.0 
 
Release
crash
0015909: segfault in destruction of static member vtkMathInternal in vtkMath
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)
No tags attached.
? valgrind.out (94,886) 2015-12-30 04:31
https://www.vtk.org/Bug/file/9988/valgrind.out
Issue History
2015-12-30 04:31Pablo Hernandez-CerdanNew Issue
2015-12-30 04:31Pablo Hernandez-CerdanFile Added: valgrind.out
2016-07-06 10:26Shawn WaldonAssigned To => Shawn Waldon
2016-07-06 10:55Shawn WaldonNote Added: 0036172
2016-07-06 10:56Shawn WaldonAssigned ToShawn Waldon =>
2016-07-06 22:55Pablo Hernandez-CerdanNote Added: 0036318
2016-07-06 22:56Pablo Hernandez-CerdanNote Edited: 0036318bug_revision_view_page.php?bugnote_id=36318#r1651
2016-08-12 09:55Kitware RobotNote Added: 0037442
2016-08-12 09:55Kitware RobotStatusbacklog => closed
2016-08-12 09:55Kitware RobotResolutionopen => moved
2016-08-12 09:55Kitware RobotAssigned To => Kitware Robot

Notes
(0036172)
Shawn Waldon   
2016-07-06 10:55   
Can you provide a simple script that can be run in valgrind to reproduce this error? My test of a common usage of vtkMath doesn't reproduce this. Since Internal is a static variable, it should be deleted at program exit which only happens once. What are you doing that is causing a double free?
(0036318)
Pablo Hernandez-Cerdan   
2016-07-06 22:55   
(edited on: 2016-07-06 22:56)
I am not able to reproduce it neither! I checked git history, checkout the closest -by date- script that I used valgrind in this bug report, but no errors. I changed the computer, if that can save me from the fire.

The valgrind output submitted here shows that no google test was running, but the memory leak exists anyway?. Maybe it was related with some google fixture... sorry, I will attach a simple script next time :(

(0037442)
Kitware Robot   
2016-08-12 09:55   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current VTK Issues page linked in the banner at the top of this page.