0

I have in test.h file: double *condmatrix - global variable Then in the main program I do:

cycle_start {
    proc1() {
    condmatrix = new double[maxdim];
    ....simple work with the array itself
    }
    proc2() {
    delete [] condmatrix;
    }
}//cycle finish

This gives me a segfault. I tried deleted with [] syntax, without and other ways, it still gives a segfault. Maxdim varies from cycle to cycle.

lhj7362
  • 2,173
  • 4
  • 19
  • 17

1 Answers1

0

Okay, I found that I allocated a pointer twice, that is:

condmatrix = new double [maxdim];
condmatrix = new double [maxdim];
delete [] condmatrix;

I know this shouldn't cause the problem, but evidently it did, because after rewriting the code to allocate once, it works perfect. Maybe there was some memory corruption, which I occasionally fixed.

lhj7362
  • 2,173
  • 4
  • 19
  • 17