CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Bugs (
-   -   SegFault due to illegal readwrites (

msg30 December 10, 2007 07:20

Hi, In template


List<t>::List(const List<t>& a)
:UList<t>(NULL, a.size_)


Foam::Field<foam::vector<double> >::Field(Foam::Field<foam::vector<double> > const&)


Foam::Field<foam::vector<double> >::Field(Foam::Field<foam::vector<double> > const&)

I have illegal reads for what I guess is the first vector (three illegal reads in the first loop iteration, all others are fine)

It is called with an internal surface vector field from autoMap() (all previous scalar fields are fine)

I have so far no idea where it comes from as the begin() member function "should" return the correct pointer I would have thought.

The only thing that confuses me so far is that you instantiate if with a field:

from the copy constructor
Field<type> fCpy(*this); // around line 490 in Field.C

Field<type>::Field(const Field<type>& f)
List<type>(f) // here f is no list but List has no copy constructor form a field and in actual fact the copy constructor from a list is used

Then later in the code there are (of course more serious) illegal writes. But I guess they have the same origin and I want to fix this first before I look at them and from a correctness point of view there is no difference between illegal reads or writes, both pests which should not be there.

I still need to learn a bit more about your coding and am at the moment a bit stuck as it seems difficult to attach gdb properly to these bits of code but will keep you posted. I would greatly appreciate any hints if you have even a vague idea what could be going on.



henry December 10, 2007 09:32

Have you tried running your co
Have you tried running your code in valgrind?

msg30 December 10, 2007 10:15

Hi Henry, thanks for the
Hi Henry,

thanks for the quick reply!

Yes, thats how I got closer to the real issue. The code only segFaults much later, but valgrind shows it right away. It is a small mesh, 2x2x2, first time step. This one runs without segFault, but if I either run more timesteps and/or increase the mesh it will eventually segFault.

Here is some of the valgrind output:

==2677== Invalid read of size 8
==2677== at 0x433695: Foam::Field<foam::vector<double> >::Field(Foam::Field<foam::vector<double> > const&) (in /home/markus/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linux64GccDPOpt/simpleFOAM )
==2677== by 0x43ABD9: Foam::Field<foam::vector<double> >::autoMap(Foam::FieldMapper const&) (in /home/markus/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linux64GccDPOpt/simpleFOAM )
==2677== by 0x578B0F6: Foam::MapInternalField<foam::vector<double>, Foam::fvMeshMapper, Foam::surfaceMesh>::operator()(Foam::Field<foam::v ector<double> >&, Foam::fvMeshMapper const&) const (MapFvSurfaceField.H:85)
==2677== by 0x578B2F0: void Foam::MapGeometricFields<foam::vector<double>, Foam::fvsPatchField, Foam::fvMeshMapper, Foam::surfaceMesh>(Foam::fvMeshMapper const&) (MapGeometricFields.H:113)
==2677== by 0x577C3DF: Foam::fvMesh::mapFields(Foam::mapPolyMesh const&) (fvMesh.C:371)
==2677== by 0x577C340: Foam::fvMesh::updateMesh(Foam::mapPolyMesh const&) (fvMesh.C:453)
==2677== by 0x82332C0: Foam::polyTopoChanger::changeMesh(bool, bool) (polyTopoChanger.C:282)
==2677== by 0x9A2FE0A: Foam::movingConeTopoFvMesh::update() (movingConeTopoFvMesh.C:364)
==2677== by 0x42CE18: main (in /home/markus/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linux64GccDPOpt/simpleFOAM )
==2677== Address 0x9CED2D0 is 0 bytes inside a block of size 864 free'd
==2677== at 0x4C212A9: operator delete[](void*) (in /usr/lib64/valgrind/amd64-linux/
==2677== by 0x57633BF: Foam::List<foam::vector<double> >::~List() (List.C:324)
==2677== by 0x576347A: Foam::Field<foam::vector<double> >::~Field() (Field.H:83)
==2677== by 0x5B73C10: void Foam::deleteDemandDrivenData<foam::field<foam::vec tor<double> >*>(Foam::Field<foam::vector<double> >*&) (demandDrivenData.H:45)
==2677== by 0x6878E17: Foam::primitiveMesh::clearGeom() (primitiveMeshClear.C:149)
==2677== by 0x6878E2E: Foam::primitiveMesh::clearAll() (primitiveMeshClear.C:199)
==2677== by 0x6875FED: Foam::primitiveMesh::reset(int, int, int, int, Foam::Field<foam::vector<double> > const&, Foam::List<foam::face> const&, Foam::List<int> const&, Foam::List<int> const&) (primitiveMesh.C:154)
==2677== by 0x6874945: Foam::polyMesh::initMesh() (polyMeshCalcFaceCells.C:175)
==2677== by 0x685EABF: Foam::polyMesh::resetPrimitives(int, Foam::Field<foam::vector<double> > const&, Foam::List<foam::face> const&, Foam::List<int> const&, Foam::List<int> const&, Foam::List<int> const&, Foam::List<int> const&, bool) (polyMesh.C:679)
==2677== by 0x82404F7: Foam::polyTopoChange::changeMesh(Foam::polyMesh&, bool, bool) (polyTopoChange.C:2684)
==2677== by 0x823327E: Foam::polyTopoChanger::changeMesh(bool, bool) (polyTopoChanger.C:279)
==2677== by 0x9A2FE0A: Foam::movingConeTopoFvMesh::update() (movingConeTopoFvMesh.C:364)

(Note, some of the line numbers may be out by a couple of lines due to debug statements / explaining comments inserted by me into the code)

mattijs December 12, 2007 08:08

Could it be that you collapse
Could it be that you collapse your mesh down to zero thickness? Looks like the problem is in mapping a surface field (e.g. phi). If you have a small testcase we can try it over here.

msg30 December 12, 2007 13:44

Dear Mattijs, Maybe I am do
Dear Mattijs,

Maybe I am doing something stupid before it comes to the segFault. Before I potentially waste more of your time, you posted a refinement mesh modifier in

If I understand it right, then, in order to use that, we have to construct our own TopoFvMesh, along the lines of movingConeTopoFvMesh for example, just without the movement, right? As you had the mesh modifier, do you have the TopoFvMesh for it as well? Maybe the source of my troubles lies there ....

Many thanks for your time!



All times are GMT -4. The time now is 06:30.