Error "munmap_chunk (): invalid pointer"

I wrote a program in Linux in Python and C ++ which I run with a script ./run.sh

. I am faced with such a strange phenomenon like this:

I first compiled my files and then executed. /run.sh -> everything is fine

  • I restart it. /run.sh -> error
  • If I recompile and rerun -> it's ok.

Thus, in order not to generate an error, I have to recompile the code before running it.

Mistake: munmap_chunk(): invalid pointer

My code is below:

float percentage = 0.0;

for (int i = 0; i < N_cubes; i++) {
    float newPercentage = i * 100.0/N_cubes;

    if ((newPercentage - percentage) >= 10.0) {
        std::cout
            << "Computing Z_CFIE_near chunk. "
            << std::floor(newPercentage)
            <<  " % completed."
            << endl;
        flush(std::cout);
        percentage = newPercentage;
    }

    // computing the local arrays
    int N_RWG_test, N_RWG_src, N_neighbors, N_nodes, S;

    blitz::Array<int, 1> test_RWGsNumbers, src_RWGsNumbers;
    blitz::Array<int, 1> neighbors_cubes;
    blitz::Array<int, 2> localTestSrcRWGNumber_signedTriangles, localTestSrcRWGNumber_nodes;
    blitz::Array<double, 2> nodesCoord;
    blitz::Array<double, 1> rCubeCenter(3);

    compute_cube_local_arrays(
        N_RWG_test,
        N_RWG_src,
        N_neighbors,
        N_nodes,
        S,
        test_RWGsNumbers,
        src_RWGsNumbers,
        neighbors_cubes,
        localTestSrcRWGNumber_signedTriangles,
        localTestSrcRWGNumber_nodes,
        nodesCoord,
        rCubeCenter,
        allCubeIntArrays(i),
        allCubeDoubleArrays(i));

    // computing the Z_CFIE
    blitz::Array<std::complex<double>, 2> Z_CFIE_J(N_RWG_test, N_RWG_src);
    blitz::Array<std::complex<float>, 1> Z_CFIE_J_linear(N_RWG_test * N_RWG_src);
}

      

In my opinion, this error is caused by the fact that Z_CFIE_J

and Z_CFIE_J_linear

cannot be freed after several loops (local variables will be freed after each loop).

Could you please give me some idea to solve this problem?

+3


source to share





All Articles