CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   *** glibc detected *** free(): invalid pointer (

carowjp February 28, 2013 22:53

*** glibc detected *** free(): invalid pointer

I working on a coding a utility, it completes, and when it ends I get this less than graceful exit:


ExecutionTime = 52.25 s  ClockTime = 54 s


*** glibc detected *** spinFoam: free(): invalid pointer: 0x0000000001791200 ***
======= Backtrace: =========
Aborted (core dumped)

Any tips on how to debug this?



wyldckat March 2, 2013 08:27

Greetings James,

That's usually due to freeing an object from memory more than once... usually crashes on the second attempt to delete the object.

Also happens if you have two libraries loaded into memory, which manipulate the same object name. Or even worst, two libraries of the same file name (or similar), using identically named classes...

Best regards,

carowjp March 5, 2013 20:52

Thanks Bruno

Thanks for the pointers...ha ha. :D


Bahram December 28, 2014 08:41


I'm trying to create a pointer list of matrices by adding following lines to icoFoam (OpenFOAM 2.3.0, Ubuntu 14.04, gcc version: 4.8.2), the code compiles with out error but I get the following run time error, How ever I tried I couldn't find the solution. Please help:

        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readPISOControls.H"
        #include "CourantNo.H"
        //*******new lines********
      PtrList<lduMatrix> PEqns(1);

            new fvScalarMatrix

        //********end new lines********

        fvVectorMatrix UEqn
          + fvm::div(phi, U)
          - fvm::laplacian(nu, U)

        solve(UEqn == -fvc::grad(p));



Create time

Create mesh for time = 0

Reading transportProperties

Reading field p

Reading field U

Reading/calculating face flux field phi

Starting time loop

Time = 0.005

Courant Number mean: 0 max: 0
smoothSolver:  Solving for Ux, Initial residual = 1, Final residual = 8.90511e-06, No Iterations 19
smoothSolver:  Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
DICPCG:  Solving for p, Initial residual = 1, Final residual = 7.55423e-07, No Iterations 35
time step continuity errors : sum local = 5.03808e-09, global = -7.94093e-21, cumulative = -7.94093e-21
DICPCG:  Solving for p, Initial residual = 0.523588, Final residual = 9.72371e-07, No Iterations 34
time step continuity errors : sum local = 1.07766e-08, global = 2.00426e-19, cumulative = 1.92485e-19
ExecutionTime = 0.01 s  ClockTime = 0 s

*** Error in `icoFoam': free(): invalid pointer: 0x0000000001931250 ***
Aborted (core dumped)

any help is appreciated.

Merry Christmas


Bahram January 7, 2015 06:41

any ideas?!

wyldckat January 11, 2015 18:26

Greetings Bahram,


Originally Posted by Bahram (Post 526397)
any ideas?!

I and plenty others on the forum have got a lot of ideas. The limitation is in fact having the necessary time to write and/or test those ideas. ;)
If you had spent the time to lay out the ideas you've tried out, it would have been easier to try and point out what you might be doing wrong. Since you didn't, it took me around 25 minutes to test, research and write this post with the answers. That might not look like a lot of time, but now multiply that by the number of posts I have on my to-do list :( I'm not the only one who answers questions here on the forum, but to me it seems we are too few to be able to answer to everyone...

Anyway, when it comes to OpenFOAM, it's best to search for similar/identical situations in its source code. I've used the following command:

find $FOAM_SOLVERS -name "*.[CH]" -type f | xargs grep PtrList
For more ideas:

And then I looked into the file "multiphase/compressibleMultiphaseInterFoam/pEqn.H". It seems that there are two things you're doing wrong:
  1. "new" is not the best solution, due to the complexity of the classes that OpenFOAM is using.
  2. "lduMatrix" is a bad class for a pointer that you tell it to store "fvScalarMatrix".
For me, the following worked just fine:

          PtrList<fvScalarMatrix> PEqns(1);

Best regards,

Bahram January 12, 2015 03:05

Dear Bruno

Thanks a lot for your nice reply and also all the time which you spend for answering our questions :). I'll give it a try.


All times are GMT -4. The time now is 19:36.