title: OpenCV double free or corruption (out): Aborted (core dumped)
body: <p>Iḿ working on a algorithm to find and fill regions on a binarized image,the code work as expected for some images, but I don't know why, after the fourth image I always get this error:</p>
  
  <blockquote>
    <p><strong>* Error in `./heli': double free or corruption (out): 0x0000000001ccb610 *</strong>
    Aborted (core dumped)</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>void fillRegion(Mat src, Mat &amp;dst, Point origin, Vec3b color)
  {
      int size = 0;
      list&lt;Point&gt; cadena;
      cadena.push_back(origin);
      while(!cadena.empty())
      {
          Point current = cadena.front();
          cadena.pop_front();
          Point top,bot,right,left;
          top = bot = right = left = current;
          top.y -= 1;
          bot.y += 1;
          right.x += 1;
          left.x -= 1;
          Vec3b cero = Vec3b(0,0,0);
  
          if(top.y &gt;= 0 &amp;&amp; dst.at&lt;Vec3b&gt;(top) == cero &amp;&amp; src.at&lt;uchar&gt;(top)!= 0)
          {
              dst.at&lt;Vec3b&gt;(top) = color;
              cadena.push_back(top);
          }
          if(bot.y &lt;= src.rows &amp;&amp; dst.at&lt;Vec3b&gt;(bot) == cero &amp;&amp; src.at&lt;uchar&gt;(bot)!= 0)
          {
              dst.at&lt;Vec3b&gt;(bot) = color;
              cadena.push_back(bot);
          }
          if(right.x &lt;= src.cols &amp;&amp; dst.at&lt;Vec3b&gt;(right) == cero &amp;&amp; src.at&lt;uchar&gt;(right)!= 0)
          {
              dst.at&lt;Vec3b&gt;(right) = color;
              cadena.push_back(right);
          }
          if(left.y &gt;= 0 &amp;&amp; dst.at&lt;Vec3b&gt;(left) == cero &amp;&amp; src.at&lt;uchar&gt;(left)!= 0)
          {
              dst.at&lt;Vec3b&gt;(left) = color;
              cadena.push_back(left);
          }
      }
  }
  
  void segment(Mat src, Mat &amp;dst)
  {
      for(int x = 0; x &lt; src.cols; x++)
      {
          for(int y = 0; y &lt; src.rows;  y++)
          {
              Point p = Point(x,y); 
              if(src.at&lt;uchar&gt;(p) != 0 &amp;&amp; dst.at&lt;Vec3b&gt;(p) == Vec3b(0,0,0) )
              {
                  fillRegion(src,dst,p,getRandomColor());
              }
          }    
      }
  }
  int main(int argc, char *argv[])
  {
      namedWindow("Original", WINDOW_NORMAL); 
      namedWindow("Resultado", WINDOW_NORMAL);
      vector&lt;string&gt; archivos = vector&lt;string&gt;();
      getdir("../images",archivos);
      int tam = archivos.size();
      for(uint i = 0; i &lt; tam; i++)
      {
          Mat img = imread(archivos[i],CV_LOAD_IMAGE_GRAYSCALE);
          Mat newImg = Mat(img.rows,img.cols, CV_8UC3, Scalar(0,0,0));;
          threshold(img,img,125,255,THRESH_BINARY);
          imshow("Original", img);
          segment(img,newImg);
          imshow("Resultado", newImg);
          waitKey(0);
      }
  }
  </code></pre>
  
  <p>I call the "Segment" method, which then calls the "fillRegion" method for each region found.
  I know the error is at the "fillRegion" method, because if I comment it from "segment", the error is gone, but I just can't find/don't know what's the error on it.</p>