title: C++ heap corruption on new
body: <p>I'm writing simple ANN (neural network) for functions' approximation. I got crash with message: "Heap corrupted". I found few advices how to resolve it, but nothing help.
  I got error at first line of this function:</p>
  
  <pre><code> void LU(double** A, double** &amp;L, double** &amp;U, int s){
      U = new double*[s];
      L = new double*[s];
      for (int i = 0; i &lt; s; i++){
          U[i] = new double[s];
          L[i] = new double[s];
          for (int j = 0; j &lt; s; j++)
              U[i][j] = A[i][j];
      }
      for (int i = 0, j = 0; i &lt; s; i = ++j){
          L[i][j] = 1;
          for (int k = i + 1; k &lt; s - 1; k++){
              L[k][j] = U[k][j] / U[i][j];
              double* vec_t = mul(U[i], L[k][j], s);
              for (int z = 0; z &lt; s; z++)
                  U[k][z] = U[k][z] - vec_t[z];
              delete[] vec_t;
          }
      }
  };
  </code></pre>
  
  <p>As I understood from debagger's information: two arrays (U and L) has been passed to function with some addresses in memory. And it's quite strange because I didn't initialize it. I call this function two times and first time it works nicely (ok, at least it works), but at second call it crashes. I have no idea how to resolve it.<br>
  There is link to whole project: <a href="https://github.com/IljaKosynkin/Aproximation" rel="nofollow">CLICK</a><br>
  I'm working in MS Visual Studio 2013 under Windows 7 x64. </p>
  
  <p><strong>UPDATE</strong><br>
  According to some commentaries below I should provide some additive information.<br>
  First of all, sorry for quality of code. I wrote it only for myself for 2 days.<br>
  Second, when I said "at second call", I mean that first I call LU when I need to get determinant of S (I use LU decomposition fot this) and it working without any crashes. Second call it's when I trying to get inverse of matrix (the same, S). And when I call detLU at [0, 0] point of matrix (to get cofactor) I got this crash.<br>
  Third, if I get information from debagger correctly, arrays L and U passes in function at second call with already defined memory's addresses. I can't understand why, becouse before LU call I have just wrote "double** L; double** U;" without any initialization.<br>
  I can try provide some additional debug information or some tests, if somebody explain me what exactly I have to do.</p>