title: error with free(): invalid next size (fast)
body: <p>I'm working on a project involving interpolation, I've implemented my interpolating functions as classes, and when I try to run my piecewise interpolation algorithm I'm getting the following error message: <code>free(): invalid next size(fast)</code> with a memory address.</p>
  
  <p>The relevant part of my main function is:</p>
  
  <pre><code>double * xx = new double [n];
  xx[0] = a;
  xx[n - 1] = b;
  for (int i=1; i&lt;n - 1; i++) xx[i] = (rand() % 1000) * (b - a) / 1000 + a;
  PwLin pv1 (n, a, b, 1, xx, 1);
  PwLin pv2 (n, a, b, 2, xx, 1);
  PwLin pv3 (n, a, b, 3, xx, 1);
  </code></pre>
  
  <p>...</p>
  
  <pre><code>cin &gt;&gt; x;
  cout &lt;&lt; pv1.eval(x) &lt;&lt; '\t' &lt;&lt; abs(f1(x, 1) - pv1.eval(x)) &lt;&lt; endl;
  cout &lt;&lt; pv2.eval(x) &lt;&lt; '\t' &lt;&lt; abs(f2(x, 1) - pv2.eval(x)) &lt;&lt; endl;
  cout &lt;&lt; pv3.eval(x) &lt;&lt; '\t' &lt;&lt; abs(f3(x, 1) - pv3.eval(x)) &lt;&lt; endl;
  </code></pre>
  
  <p>The PwLin class is</p>
  
  <pre><code>class PwLin
  {
  double * xl, * yl, * h;
  double a, b;
  int n;
  bool uni;
  public:
  double eval(double);
  PwLin(int, double, double, int, double);
  PwLin(int, double, double, int, double *, double);
  ~PwLin(){};
  };
  </code></pre>
  
  <p>and the eval() function is</p>
  
  <pre><code>double PwLin::eval(double x)
  {
  int i=0;
  while (x &gt; xl[i]) i++;
  if (uni == 1){
  return (yl[i - 1] * (xl[i] - x) + yl[i] * (x - xl[i - 1])) / h[0]; }
  else return (yl[i - 1] * (xl[i] - x) + yl[i] * (x - xl[i])) / h[i];
  }
  </code></pre>
  
  <p>I've searched a bit and found that the <code>free(): invalid next size</code> error is caused by a memory leak, but I have no idea where it is.  When I run the function the error doesn't occur until I enter an x value to test, so it seems to be an issue with the <code>eval()</code> function rather than the constructor, but I don't have any memory actions at all in <code>eval()</code> or in the while loop, I have no idea what the problem is.</p>
  
  <p>and uh, I installed ubuntu last week and have no idea how to use it, I'm using gedit which afaik has no debugging utility and if there's anything fancier in ubuntu I don't know what it is</p>