*** stack smashing detected *** error at the return of a function using FEAST
<p>I have a long program in which I have a function for calculating eigenvalues of a large matrix using FEAST. Right at the return of that function I get a <strong>* stack smashing detected *</strong> error and I lose all the results. Here is my the function </p>

<pre><code>    void Model::eigensolver(double* val, int* ia, int* ja, const int n, int m0, std::string outfilename)
{
// compute Eigenvalues and Eigenvectors by calling FEAST library from MKL
const char uplo='U';
MKL_INT fpm[128], loop;
feastinit(fpm);
//fpm[0]=1;
const double emin=-1,emax=100;
MKL_INT eig_found=0;
double res,epsout;
double *eigenvalues= new double [m0];
double *eig_vec = new double [m0*_dof];
int info;
std::cout &lt;&lt; "Everything ready, making call to FEAST." &lt;&lt; std::endl;
dfeast_scsrev(&amp;uplo, &amp;n, val, ia, ja, fpm, &amp;epsout, &amp;loop, &amp;emin, &amp;emax, &amp;m0, eigenvalues, eig_vec, &amp;eig_found, &amp;res, &amp;info );
if (info != 0) {
  std::cout &lt;&lt; "Something is wrong in eigensolver. Info=" &lt;&lt; info &lt;&lt; std::endl;
  exit(0);
}

std::cout &lt;&lt; loop &lt;&lt; " iterations taken to converge." &lt;&lt; std::endl;
std::cout &lt;&lt; eig_found &lt;&lt; " eigenvalues found in the interval." &lt;&lt; std::endl;
std::ofstream evals;
evals.open("evals.dat");
std::cout&lt;&lt;"The eigenfrequencies are:"&lt;&lt;std::endl;
for (int i = 0; i &lt; eig_found; i++) 
  evals &lt;&lt; eigenvalues[i] &lt;&lt; std::endl;
evals.close();
delete[] eigenvalues;
delete[] eig_vec;
std::cout &lt;&lt; "Writen eigenvalues to file evals.dat." &lt;&lt; std::endl;
return;
}
</code></pre>

<p>The dfeast_scsrev is a function from FEAST library (also part of intel MKL). The error happens right at the return (i.e. after the "Written eigenvalues to file evals.dat." is printing). Depending on the problem I run, sometimes I also get segmentation fault right at the same point.</p>

<p>If I remove the FEAST function call, there is no error. So, I am confused what I am doing wrong. I am trying valgrind, but because of the size of my code, it is taking a long time to run.</p>