← Back to team overview

dolfin team mailing list archive

Re: Memory problem inside FunctionSpace

 

Garth N. Wells wrote:

Bartosz Sawicki wrote:
It seems that IntersectionDetector is not deleted properly, when for new object is created in FunctionSpace.cpp:120 :

  // Initialize intersection detector if not done before
  if (!intersection_detector)
    intersection_detector = new IntersectionDetector(*_mesh);.

I've reduce the problem to very simple example, where only valgrind realize the error. But in real application, it lead my software to
segmentation faults.

Can anyone confirm this?


There's a problem with your code.

    Function j( FunctionSpace(mesh, fe, dofmap) );

should be

    FunctionSpace V(mesh, fe, dofmap);
    Function j(V);


Thank you very much.
Separated FunctionSpace object solved the problem.
Code works, valgrind confirm its correctness.

BArtek



Garth


BArtek


Bartosz Sawicki wrote:
 From hg repository. pull&update 15 minutes ago.

BArtek


Garth N. Wells wrote:
Which version of DOLFIN are you using?

Garth

Bartosz Sawicki wrote:
I realized strange problem in my code when Function is created using FiniteElement and DofMap. PETSc have reported memory problems, but it is difficult to repeat. I'm not able to locate the error, but it seems that the bug is inside the FunctionSpace.

Please consider following code. It compiles, it works works, but Valgrind reports errors.

================

#include <dolfin.h>

using namespace dolfin;

int main (int argc, char **argv) {

   UnitCube mesh(10,10,10);

   FiniteElement fe("FiniteElement('Lagrange', 'tetrahedron', 1)");
DofMap dofmap("FFC dof map for FiniteElement('Lagrange', 'tetrahedron', 1)", mesh);

   Function j( FunctionSpace(mesh, fe, dofmap) );

   j.vector() = 1.0;


   Point point( 0.5, 0.5, 0.5);
   Point value;

   j.eval((double *)value.coordinates(), point.coordinates());

   std::cout << value[0] << std::endl;

   return 0;
}
================

$ ./demo
1

$ valgrind ./demo
==20870== Memcheck, a memory error detector.
==20870== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al. ==20870== Using LibVEX rev 1854, a library for dynamic binary translation.
==20870== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==20870== Using valgrind-3.3.1-Debian, a dynamic binary instrumentation framework. ==20870== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==20870== For more details, rerun with: -v
==20870==
==20870== Invalid write of size 8
==20870== at 0x4825B8A: VecGetValues_Seq (in /usr/lib/libpetscvec.so.2.3.3) ==20870== by 0x4851887: VecGetValues (in /usr/lib/libpetscvec.so.2.3.3) ==20870== by 0x41EAD22: dolfin::PETScVector::get(double*, unsigned, unsigned const*) const (PETScVector.cpp:144) ==20870== by 0x4188024: dolfin::Function::interpolate(double*, dolfin::FunctionSpace const&, ufc::cell const&, unsigned, int) const (Function.cpp:266) ==20870== by 0x418041B: dolfin::FunctionSpace::eval(double*, double const*, dolfin::Function const&, ufc::cell const&, unsigned) const (FunctionSpace.cpp:149) ==20870== by 0x41842D6: dolfin::FunctionSpace::eval(double*, double const*, dolfin::Function const&) const (FunctionSpace.cpp:132) ==20870== by 0x41886DA: dolfin::Function::eval(double*, double const*) const (Function.cpp:206)
==20870==    by 0x8054EEF: main (main.cpp:38)
==20870== Address 0x64f71d8 is 0 bytes inside a block of size 32 free'd ==20870== at 0x40241AA: operator delete[](void*) (vg_replace_malloc.c:364) ==20870== by 0x4180107: dolfin::FunctionSpace::Scratch::~Scratch() (FunctionSpace.cpp:302) ==20870== by 0x4180A98: dolfin::FunctionSpace::~FunctionSpace() (FunctionSpace.cpp:64)
==20870==    by 0x8054E82: main (main.cpp:22)
==20870==
==20870== Invalid write of size 8
==20870== at 0x40ED491: ffc_04_finite_element_0::evaluate_basis(unsigned, double*, double const*, ufc::cell const&) const (ffc_04.h:173) ==20870== by 0x4180496: dolfin::FunctionSpace::eval(double*, double const*, dolfin::Function const&, ufc::cell const&, unsigned) const (FiniteElement.h:60) ==20870== by 0x41842D6: dolfin::FunctionSpace::eval(double*, double const*, dolfin::Function const&) const (FunctionSpace.cpp:132) ==20870== by 0x41886DA: dolfin::Function::eval(double*, double const*) const (Function.cpp:206)
==20870==    by 0x8054EEF: main (main.cpp:38)
==20870== Address 0x64f7228 is 0 bytes inside a block of size 8 free'd ==20870== at 0x40241AA: operator delete[](void*) (vg_replace_malloc.c:364) ==20870== by 0x4180116: dolfin::FunctionSpace::Scratch::~Scratch() (FunctionSpace.cpp:303) ==20870== by 0x4180A98: dolfin::FunctionSpace::~FunctionSpace() (FunctionSpace.cpp:64)
==20870==    by 0x8054E82: main (main.cpp:22)
==20870==
==20870== Invalid read of size 8
==20870== at 0x41804B8: dolfin::FunctionSpace::eval(double*, double const*, dolfin::Function const&, ufc::cell const&, unsigned) const (FunctionSpace.cpp:158) ==20870== by 0x41842D6: dolfin::FunctionSpace::eval(double*, double const*, dolfin::Function const&) const (FunctionSpace.cpp:132) ==20870== by 0x41886DA: dolfin::Function::eval(double*, double const*) const (Function.cpp:206)
==20870==    by 0x8054EEF: main (main.cpp:38)
==20870== Address 0x64f71d8 is 0 bytes inside a block of size 32 free'd ==20870== at 0x40241AA: operator delete[](void*) (vg_replace_malloc.c:364) ==20870== by 0x4180107: dolfin::FunctionSpace::Scratch::~Scratch() (FunctionSpace.cpp:302) ==20870== by 0x4180A98: dolfin::FunctionSpace::~FunctionSpace() (FunctionSpace.cpp:64)
==20870==    by 0x8054E82: main (main.cpp:22)
==20870==
==20870== Invalid read of size 8
==20870== at 0x41804BB: dolfin::FunctionSpace::eval(double*, double const*, dolfin::Function const&, ufc::cell const&, unsigned) const (FunctionSpace.cpp:158) ==20870== by 0x41842D6: dolfin::FunctionSpace::eval(double*, double const*, dolfin::Function const&) const (FunctionSpace.cpp:132) ==20870== by 0x41886DA: dolfin::Function::eval(double*, double const*) const (Function.cpp:206)
==20870==    by 0x8054EEF: main (main.cpp:38)
==20870== Address 0x64f7228 is 0 bytes inside a block of size 8 free'd ==20870== at 0x40241AA: operator delete[](void*) (vg_replace_malloc.c:364) ==20870== by 0x4180116: dolfin::FunctionSpace::Scratch::~Scratch() (FunctionSpace.cpp:303) ==20870== by 0x4180A98: dolfin::FunctionSpace::~FunctionSpace() (FunctionSpace.cpp:64)
==20870==    by 0x8054E82: main (main.cpp:22)
1
==20870==
==20870== ERROR SUMMARY: 16 errors from 4 contexts (suppressed: 353 from 2)
==20870== malloc/free: in use at exit: 16 bytes in 2 blocks.
==20870== malloc/free: 463 allocs, 461 frees, 168,090 bytes allocated.
==20870== For counts of detected errors, rerun with: -v
==20870== searching for pointers to 2 not-freed blocks.
==20870== checked 4,507,820 bytes.
==20870==
==20870== LEAK SUMMARY:
==20870==    definitely lost: 16 bytes in 2 blocks.
==20870==      possibly lost: 0 bytes in 0 blocks.
==20870==    still reachable: 0 bytes in 0 blocks.
==20870==         suppressed: 0 bytes in 0 blocks.
==20870== Rerun with --leak-check=full to see details of leaked memory.


BArtek
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev

_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev




References