title: malloc.c:2451 in a program using an std::vector of vectors
body: <p>In an attempt to implement an algorithm which finds the Eigenvalues of a matrix, I run into a problem: The program must, in a matter of successive iterations, build up two auxiliary matrices. (called t_mat and s_mat in my program). In order to so, I decided to use an std::vector of std::vectors, which should have equal length.
  What I am then trying to do, is at each step:</p>
  
  <p>1) Increase all the vectors by one row, value 0.0</p>
  
  <p>2) Add a new vector at the end with all elements 0.0</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>unsigned j_=0;
  while (conv_measure &gt; 0.001){
      (...)
          std::cout &lt;&lt; "Step 5" &lt;&lt; std::endl;
          unsigned temp_mat_size= t_mat.size();
          std::cout &lt;&lt; "CP 1" &lt;&lt; std::endl;
          std::cout &lt;&lt; "temp mat size " &lt;&lt; temp_mat_size &lt;&lt; std::endl;
          for (size_t l_=0; l_ &lt; temp_mat_size; l_++)
          {
              t_mat[l_].push_back(0.0); //Enlarge each vector by one row.
              s_mat[l_].push_back(0.0);
          }
          std::cout &lt;&lt; "CP 2" &lt;&lt; std::endl;
          vec_cont_t next_vec (temp_mat_size+1, 0.0); //matrix_size +1 entries with value 0.0
          std::cout &lt;&lt; "CP 3" &lt;&lt; std::endl;
          t_mat.push_back(next_vec);
          s_mat.push_back(next_vec);
      (...)
  }
  </code></pre>
  
  <p>Please ignore all the std::cout statements. These were only used to hunt down the error.
  The program performs fine for exactly three iterations. (So the above code works three times). At the fourth iteration, the program crashes in eclipse with the message:</p>
  
  <pre><code>Band_Lanczos: malloc.c:2451: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &amp;((av)-&gt;bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) &amp;&amp; old_size == 0) || ((unsigned long) (old_size) &gt;= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) &amp; ~((2 * (sizeof(size_t))) - 1))) &amp;&amp; ((old_top)-&gt;size &amp; 0x1) &amp;&amp; ((unsigned long)old_end &amp; pagemask) == 0)' failed.
  </code></pre>
  
  <p>Unfortunately, I am still a beginner when it comes to C++, especially to debugging. I don't understand anything of what that message is trying to tell me, or why the program crashes in the first place. I don't understand why it works 3 times and then suddenly goes down. The space requirements for a 4x4 matrix of doubles aren't big enough to take up all available memory. I read elsewhere that I should be using Valgrind to solve this, but this exceeds my skills.</p>